vec-lens-0.3: Vec: length-indexed (sized) list: lens support

Safe HaskellNone
LanguageHaskell2010

Data.Vec.Lazy.Inline.Lens

Contents

Synopsis

Indexing

ix :: forall n f a. (InlineInduction n, Functor f) => Fin n -> LensLike' f (Vec n a) a Source #

Index lens.

>>> ('a' ::: 'b' ::: 'c' ::: VNil) ^. ix (FS FZ)
'b'
>>> ('a' ::: 'b' ::: 'c' ::: VNil) & ix (FS FZ) .~ 'x'
'a' ::: 'x' ::: 'c' ::: VNil

_Cons :: Iso (Vec (S n) a) (Vec (S n) b) (a, Vec n a) (b, Vec n b) Source #

Match on non-empty Vec.

Note: lens _Cons is a Prism. In fact, Vec n a cannot have an instance of Cons as types don't match.

_head :: Lens' (Vec (S n) a) a Source #

Head lens. Note: lens _head is a Traversal'.

>>> ('a' ::: 'b' ::: 'c' ::: VNil) ^. _head
'a'
>>> ('a' ::: 'b' ::: 'c' ::: VNil) & _head .~ 'x'
'x' ::: 'b' ::: 'c' ::: VNil

_tail :: Lens' (Vec (S n) a) (Vec n a) Source #

Tail lens.

Conversions

_Pull :: InlineInduction n => Iso (Vec n a) (Vec n b) (Vec n a) (Vec n b) Source #

An Iso from toPull and fromPull.

_Vec :: InlineInduction n => Prism' [a] (Vec n a) Source #

Prism from list.

>>> "foo" ^? _Vec :: Maybe (Vec N.Nat3 Char)
Just ('f' ::: 'o' ::: 'o' ::: VNil)
>>> "foo" ^? _Vec :: Maybe (Vec N.Nat2 Char)
Nothing
>>> _Vec # (True ::: False ::: VNil)
[True,False]