diff --git a/src/Control/Lens/Lens.idr b/src/Control/Lens/Lens.idr index 648dbad..edd738d 100644 --- a/src/Control/Lens/Lens.idr +++ b/src/Control/Lens/Lens.idr @@ -154,7 +154,7 @@ infix 4 <||=; infix 4 <&&=; infix 4 <<+>= infix 4 <<%=; infix 4 <<%@=; infix 4 <<.=; infix 4 <= -infixr 2 <<~ +infixr 1 <<<~ public export @@ -403,11 +403,8 @@ public export ||| Run a monadic action and set the focus of an optic in state to the result. -||| This is different from `(<~)` in that it also passes though the output of -||| the action. +||| This is different from `(<~)` and `(<<~)` in that it also passes though +||| the old value of the optic. public export -(<<~) : MonadState s m => Lens s s a b -> m b -> m b -(<<~) l x = do - v <- x - modify $ l @{MkIsLens Function} (const v) - pure v +(<<<~) : MonadState s m => Lens s s a b -> m b -> m a +(<<<~) l m = l <<.= !m diff --git a/src/Control/Lens/Setter.idr b/src/Control/Lens/Setter.idr index 068e411..cd82eb5 100644 --- a/src/Control/Lens/Setter.idr +++ b/src/Control/Lens/Setter.idr @@ -157,6 +157,8 @@ infix 4 %=; infix 4 %@=; infix 4 .=; infix 4 .@=; infix 4 ?=; infix 4 <.= infix 4 = +infix 1 <~ +infixr 1 <<~ ||| Set the focus of an optic to `Just` a value. public export @@ -303,4 +305,11 @@ public export ||| variable. public export (<~) : MonadState s m => Setter s s a b -> m b -> m () -(<~) l m = m >>= (l .=) +(<~) l m = l .= !m + +||| Run a monadic action and set the focus of an optic in state to the result. +||| This is different from `(<~)` in that it also passes though the output of +||| the action. +public export +(<<~) : MonadState s m => Setter s s a b -> m b -> m b +(<<~) l m = l <.= !m