optics-core-0.4.1.1: Optics as an abstract interface: core definitions
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Sequence.Optics

Description

This module defines optics for constructing and manipulating finite Seqs.

Synopsis

Documentation

viewL :: Iso (Seq a) (Seq b) (ViewL a) (ViewL b) Source #

A Seq is isomorphic to a ViewL

viewl m ≡ m ^. viewL
>>> Seq.fromList [1,2,3] ^. viewL
1 :< fromList [2,3]
>>> Seq.empty ^. viewL
EmptyL
>>> EmptyL ^. re viewL
fromList []
>>> review viewL $ 1 Seq.:< Seq.fromList [2,3]
fromList [1,2,3]

viewR :: Iso (Seq a) (Seq b) (ViewR a) (ViewR b) Source #

A Seq is isomorphic to a ViewR

viewr m ≡ m ^. viewR
>>> Seq.fromList [1,2,3] ^. viewR
fromList [1,2] :> 3
>>> Seq.empty ^. viewR
EmptyR
>>> EmptyR ^. re viewR
fromList []
>>> review viewR $ Seq.fromList [1,2] Seq.:> 3
fromList [1,2,3]

sliced :: Int -> Int -> IxTraversal' Int (Seq a) a Source #

Traverse all the elements numbered from i to j of a Seq

>>> Seq.fromList [1,2,3,4,5] & sliced 1 3 %~ (*10)
fromList [1,20,30,4,5]
>>> Seq.fromList [1,2,3,4,5] ^.. sliced 1 3
[2,3]
>>> Seq.fromList [1,2,3,4,5] & sliced 1 3 .~ 0
fromList [1,0,0,4,5]

slicedTo :: Int -> IxTraversal' Int (Seq a) a Source #

Traverse the first n elements of a Seq

>>> Seq.fromList [1,2,3,4,5] ^.. slicedTo 2
[1,2]
>>> Seq.fromList [1,2,3,4,5] & slicedTo 2 %~ (*10)
fromList [10,20,3,4,5]
>>> Seq.fromList [1,2,4,5,6] & slicedTo 10 .~ 0
fromList [0,0,0,0,0]

slicedFrom :: Int -> IxTraversal' Int (Seq a) a Source #

Traverse all but the first n elements of a Seq

>>> Seq.fromList [1,2,3,4,5] ^.. slicedFrom 2
[3,4,5]
>>> Seq.fromList [1,2,3,4,5] & slicedFrom 2 %~ (*10)
fromList [1,2,30,40,50]
>>> Seq.fromList [1,2,3,4,5] & slicedFrom 10 .~ 0
fromList [1,2,3,4,5]

seqOf :: Is k A_Fold => Optic' k is s a -> s -> Seq a Source #

Construct a Seq from a fold.

>>> seqOf folded ["hello","world"]
fromList ["hello","world"]
>>> seqOf (folded % _2) [("hello",1),("world",2),("!!!",3)]
fromList [1,2,3]