lens-5.2.3: Lenses, Folds and Traversals

Copyright | (C) 2012-16 Edward Kmett
License | BSD-style (see the file LICENSE)
Maintainer | Edward Kmett <ekmett@gmail.com>
Stability | experimental
Portability | non-portable
Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.Sequence.Lens

Description

Synopsis

- viewL :: forall a b p f. (Profunctor p, Functor f) => p (ViewL a) (f (ViewL b)) -> p (Seq a) (f (Seq b))
- viewR :: forall a b p f. (Profunctor p, Functor f) => p (ViewR a) (f (ViewR b)) -> p (Seq a) (f (Seq b))
- sliced :: Int -> Int -> IndexedTraversal' Int (Seq a) a
- slicedTo :: Int -> IndexedTraversal' Int (Seq a) a
- slicedFrom :: Int -> IndexedTraversal' Int (Seq a) a
- seqOf :: Getting (Seq a) s a -> s -> Seq a

# Documentation

viewL :: forall a b p f. (Profunctor p, Functor f) => p (ViewL a) (f (ViewL b)) -> p (Seq a) (f (Seq b)) #

A `Seq` is isomorphic to a `ViewL`

    viewl m ≡ m ^. viewL

    >>> Seq.fromList [a,b,c] ^. viewL
    a :< fromList [b,c]

    >>> Seq.empty ^. viewL
    EmptyL

    >>> EmptyL ^. from viewL
    fromList []

    >>> review viewL $ a Seq.:< Seq.fromList [b,c]
    fromList [a,b,c]

viewR :: forall a b p f. (Profunctor p, Functor f) => p (ViewR a) (f (ViewR b)) -> p (Seq a) (f (Seq b)) #

A `Seq` is isomorphic to a `ViewR`

    viewr m ≡ m ^. viewR

    >>> Seq.fromList [a,b,c] ^. viewR
    fromList [a,b] :> c

    >>> Seq.empty ^. viewR
    EmptyR

    >>> EmptyR ^. from viewR
    fromList []

    >>> review viewR $ Seq.fromList [a,b] Seq.:> c
    fromList [a,b,c]

sliced :: Int -> Int -> IndexedTraversal' Int (Seq a) a #

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

    >>> Seq.fromList [a,b,c,d,e] & sliced 1 3 %~ f
    fromList [a,f b,f c,d,e]

slicedTo :: Int -> IndexedTraversal' Int (Seq a) a #

Traverse the first `n` elements of a `Seq`

    >>> Seq.fromList [a,b,c,d,e] ^.. slicedTo 2
    [a,b]

    >>> Seq.fromList [a,b,c,d,e] & slicedTo 2 %~ f
    fromList [f a,f b,c,d,e]

    >>> Seq.fromList [a,b,c,d,e] & slicedTo 10 .~ x
    fromList [x,x,x,x,x]

slicedFrom :: Int -> IndexedTraversal' Int (Seq a) a #

Traverse all but the first `n` elements of a `Seq`

    >>> Seq.fromList [a,b,c,d,e] ^.. slicedFrom 2
    [c,d,e]

    >>> Seq.fromList [a,b,c,d,e] & slicedFrom 2 %~ f
    fromList [a,b,f c,f d,f e]

    >>> Seq.fromList [a,b,c,d,e] & slicedFrom 10 .~ x
    fromList [a,b,c,d,e]

seqOf :: Getting (Seq a) s a -> s -> Seq a #

Construct a `Seq` from a `Getter`, `Fold`, `Traversal`, `Lens` or `Iso`.

    >>> seqOf folded ["hello","world"]
    fromList ["hello","world"]

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

    seqOf :: Getter s a    -> s -> Seq a
    seqOf :: Fold s a      -> s -> Seq a
    seqOf :: Iso' s a       -> s -> Seq a
    seqOf :: Lens' s a      -> s -> Seq a
    seqOf :: Traversal' s a -> s -> Seq a