Skip to content

Commit

Permalink
Fix typos and improve docs for Control.Lens.Cons
Browse files Browse the repository at this point in the history
  • Loading branch information
meooow25 authored and RyanGlScott committed Nov 8, 2024
1 parent 78caf61 commit 0ef83b7
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions src/Control/Lens/Cons.hs
Original file line number Diff line number Diff line change
Expand Up @@ -330,45 +330,43 @@ _tail :: Cons s s a a => Traversal' s s
_tail = _Cons._2
{-# INLINE _tail #-}

-- | Modify the target of a 'Cons' value by using @('<|')@.
-- | Modify the target(s) of a 'Lens'', 'Iso', 'Setter' or 'Traversal' using @('<|')@.
--
-- >>> (["world"], ["lens"]) & _1 <|~ "hello"
-- (["hello","world"],["lens"])
(<|~) :: Cons b b a a => ASetter s t b b -> a -> s -> t
l <|~ n = over l (n <|)
{-# INLINE (<|~) #-}

-- | Modify the target(s) of a 'Lens'', 'Iso', 'Setter' or 'Traversal' by using @('<|')@.
-- | Modify the target(s) of a 'Lens'', 'Iso', 'Setter' or 'Traversal' using @('<|')@.
(<|=) :: (MonadState s m, Cons b b a a) => ASetter s s b b -> a -> m ()
l <|= a = State.modify (l <|~ a)
{-# INLINE (<|=) #-}

-- | ('<|') a 'Cons' value onto the end of the target of a 'Lens' and
-- return the result.
-- | ('<|') a value onto the target of a 'Lens' and return the result.
--
-- When you do not need the result of the operation, ('Control.Lens.Cons.<|~') is more flexible.
(<<|~) :: Cons b b a a => LensLike ((,) b) s t b b -> a -> s -> (b, t)
l <<|~ m = l <%~ (m <|)
{-# INLINE (<<|~) #-}

-- | ('<|') a 'Cons' value onto the end of the target of a 'Lens' and
-- return the /old/ result.
-- | ('<|') a value onto the target of a 'Lens' and return the /old/ result.
--
-- When you do not need the result of the operation, ('Control.Lens.Cons.<|~') is more flexible.
(<<<|~) :: Cons b b a a => LensLike' ((,) b) s b -> a -> s -> (b, s)
l <<<|~ m = l <<%~ (m <|)
{-# INLINE (<<<|~) #-}

-- | ('<|') a 'Semigroup' value onto the end of the target of a 'Lens' into
-- your 'Monad''s state and return the result.
-- | ('<|') a value onto the target of a 'Lens' into your 'Monad'\'s state and
-- return the result.
--
-- When you do not need the result of the operation, ('Control.Lens.Cons.<|=') is more flexible.
(<<|=) :: (MonadState s m, Cons b b a a) => LensLike ((,) b) s s b b -> a -> m b
l <<|= r = l <%= (r <|)
{-# INLINE (<<|=) #-}

-- | ('<|') a 'Semigroup' value onto the end of the target of a 'Lens' into
-- your 'Monad''s state and return the /old/ result.
-- | ('<|') a value onto the target of a 'Lens' into your 'Monad'\'s state and
-- return the /old/ result.
--
-- When you do not need the result of the operation, ('Control.Lens.Cons.<|=') is more flexible.
(<<<|=) :: (MonadState s m, Cons b b a a) => LensLike ((,) b) s s b b -> a -> m b
Expand Down Expand Up @@ -544,7 +542,7 @@ _last :: Snoc s s a a => Traversal' s a
_last = _Snoc._2
{-# INLINE _last #-}

-- | 'snoc' an element onto the end of a container.
-- | 'snoc' an element onto a container.
--
-- This is an infix alias for 'snoc'.
--
Expand All @@ -560,7 +558,7 @@ _last = _Snoc._2
(|>) = curry (simply review _Snoc)
{-# INLINE (|>) #-}

-- | 'snoc' an element onto the end of a container.
-- | 'snoc' an element onto a container.
--
-- >>> snoc (Seq.fromList []) a
-- fromList [a]
Expand Down Expand Up @@ -591,45 +589,43 @@ unsnoc :: Snoc s s a a => s -> Maybe (s, a)
unsnoc = simply preview _Snoc
{-# INLINE unsnoc #-}

-- | Modify the target of a 'Cons' value by using @('|>')@.
-- | Modify the target(s) of a 'Lens'', 'Iso', 'Setter' or 'Traversal' using @('|>')@.
--
-- >>> (["world"], ["lens"]) & _1 |>~ "hello"
-- (["world","hello"],["lens"])
(|>~) :: Snoc b b a a => ASetter s t b b -> a -> s -> t
l |>~ n = over l (|> n)
{-# INLINE (|>~) #-}

-- | Modify the target(s) of a 'Lens'', 'Iso', 'Setter' or 'Traversal' by using @('|>')@.
-- | Modify the target(s) of a 'Lens'', 'Iso', 'Setter' or 'Traversal' using @('|>')@.
(|>=) :: (MonadState s m, Snoc b b a a) => ASetter s s b b -> a -> m ()
l |>= a = State.modify (l |>~ a)
{-# INLINE (|>=) #-}

-- | ('|>') a 'Cons' value onto the end of the target of a 'Lens' and
-- return the result.
-- | ('|>') a value onto the target of a 'Lens' and return the result.
--
-- When you do not need the result of the operation, ('Control.Lens.Cons.|>~') is more flexible.
(<|>~) :: Snoc b b p p => LensLike ((,) b) s t b b -> p -> s -> (b, t)
l <|>~ m = l <%~ (|> m)
{-# INLINE (<|>~) #-}

-- | ('|>') a 'Cons' value onto the end of the target of a 'Lens' and
-- return the /old/ result.
-- | ('|>') a value onto the target of a 'Lens' and return the /old/ result.
--
-- When you do not need the result of the operation, ('Control.Lens.Cons.|>~') is more flexible.
(<<|>~) :: Snoc b b p p => LensLike' ((,) b) s b -> p -> s -> (b, s)
l <<|>~ m = l <<%~ (|> m)
{-# INLINE (<<|>~) #-}

-- | ('|>') a 'Semigroup' value onto the end of the target of a 'Lens' into
-- your 'Monad''s state and return the result.
-- | ('|>') a value onto the target of a 'Lens' into your 'Monad'\'s state and
-- return the result.
--
-- When you do not need the result of the operation, ('Control.Lens.Cons.|>=') is more flexible.
(<|>=) :: (MonadState s m, Snoc b b p p) => LensLike ((,) b) s s b b -> p -> m b
l <|>= r = l <%= (|> r)
{-# INLINE (<|>=) #-}

-- | ('|>') a 'Semigroup' value onto the end of the target of a 'Lens' into
-- your 'Monad''s state and return the result.
-- | ('|>') a value onto the target of a 'Lens' into your 'Monad'\'s state and
-- return the /old/ result.
--
-- When you do not need the result of the operation, ('Control.Lens.Cons.|>=') is more flexible.
(<<|>=) :: (MonadState s m, Snoc b b p p) => LensLike ((,) b) s s b b -> p -> m b
Expand Down

0 comments on commit 0ef83b7

Please sign in to comment.