'mapException' ≡ 'over' 'mappedException'This view that every Haskell expression can be regarded as carrying a bag of Exceptions is detailed in “A Semantics for Imprecise Exceptions” by Peyton Jones & al. at PLDI ’99. The following maps failed assertions to arithmetic overflow:
>>> handling _Overflow (\_ -> return "caught") $ assert False (return "uncaught") & mappedException %~ \ (AssertionFailed _) -> Overflow "caught"
>>> handling _Overflow (\_ -> return "caught") $ assert False (return "uncaught") & mappedException' .~ Overflow "caught"
mapAccumL ≡ mapAccumLOf traversemapAccumLOf accumulates State from left to right.
mapAccumLOf :: Iso s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t) mapAccumLOf :: Lens s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t) mapAccumLOf :: Traversal s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
mapAccumLOf :: LensLike (State acc) s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t) mapAccumLOf l f acc0 s = swap (runState (l (a -> state (acc -> swap (f acc a))) s) acc0)
mapAccumR ≡ mapAccumROf traversemapAccumROf accumulates State from right to left.
mapAccumROf :: Iso s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t) mapAccumROf :: Lens s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t) mapAccumROf :: Traversal s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
mapAccumROf :: LensLike (Backwards (State acc)) s t a b -> (acc -> a -> (acc, b)) -> acc -> s -> (acc, t)
>>> mapMOf both (\x -> [x, x + 1]) (1,3) [(1,3),(1,4),(2,3),(2,4)]
mapM ≡ mapMOf traverse imapMOf l ≡ forM l . Indexed
mapMOf :: Monad m => Iso s t a b -> (a -> m b) -> s -> m t mapMOf :: Monad m => Lens s t a b -> (a -> m b) -> s -> m t mapMOf :: Monad m => Traversal s t a b -> (a -> m b) -> s -> m t
>>> mapMOf_ both putStrLn ("hello","world") hello world
mapM_ ≡ mapMOf_ folded
mapMOf_ :: Monad m => Getter s a -> (a -> m r) -> s -> m () mapMOf_ :: Monad m => Fold s a -> (a -> m r) -> s -> m () mapMOf_ :: Monad m => Lens' s a -> (a -> m r) -> s -> m () mapMOf_ :: Monad m => Iso' s a -> (a -> m r) -> s -> m () mapMOf_ :: Monad m => Traversal' s a -> (a -> m r) -> s -> m () mapMOf_ :: Monad m => Prism' s a -> (a -> m r) -> s -> m ()
fmap ≡ over mapped fmapDefault ≡ over traverse (<$) ≡ set mapped
>>> over mapped f [a,b,c] [f a,f b,f c]
>>> over mapped (+1) [1,2,3] [2,3,4]
>>> set mapped x [a,b,c] [x,x,x]
>>> [[a,b],[c]] & mapped.mapped +~ x [[a + x,b + x],[c + x]]
>>> over (mapped._2) length [("hello","world"),("leaders","!!!")] [("hello",5),("leaders",3)]
mapped :: Functor f => Setter (f a) (f b) a bIf you want an IndexPreservingSetter use setting fmap.
>>> concatMapOf both (\x -> [x, x + 1]) (1,3) [1,2,3,4]
concatMap ≡ concatMapOf folded
concatMapOf :: Getter s a -> (a -> [r]) -> s -> [r] concatMapOf :: Fold s a -> (a -> [r]) -> s -> [r] concatMapOf :: Lens' s a -> (a -> [r]) -> s -> [r] concatMapOf :: Iso' s a -> (a -> [r]) -> s -> [r] concatMapOf :: Traversal' s a -> (a -> [r]) -> s -> [r]
contramap ≡ over contramapped
>>> getPredicate (over contramapped (*2) (Predicate even)) 5 True
>>> getOp (over contramapped (*5) (Op show)) 100 "500"
>>> Prelude.map ($ 1) $ over (mapped . _Unwrapping' Op . contramapped) (*12) [(*2),(+1),(^3)] [24,13,1728]
contramapping :: Contravariant f => Iso s t a b -> Iso (f a) (f b) (f s) (f t) contramapping :: Contravariant f => Iso' s a -> Iso' (f a) (f s)
dimapping :: Profunctor p => Iso s t a b -> Iso s' t' a' b' -> Iso (p a s') (p b t') (p s a') (p t b') dimapping :: Profunctor p => Iso' s a -> Iso' s' a' -> Iso' (p a s') (p s a')
foldMapByOf folded ≡ foldMapBy
foldMapByOf :: Getter s a -> (r -> r -> r) -> r -> (a -> r) -> s -> r foldMapByOf :: Fold s a -> (r -> r -> r) -> r -> (a -> r) -> s -> r foldMapByOf :: Traversal' s a -> (r -> r -> r) -> r -> (a -> r) -> s -> r foldMapByOf :: Lens' s a -> (r -> r -> r) -> r -> (a -> r) -> s -> r foldMapByOf :: Iso' s a -> (r -> r -> r) -> r -> (a -> r) -> s -> r
>>> foldMapByOf both (+) 0 length ("hello","world") 10
>>> foldMapOf (folded . both . _Just) Sum [(Just 21, Just 21)] Sum {getSum = 42}
foldMap = foldMapOf folded
foldMapOf ≡ views ifoldMapOf l = foldMapOf l . Indexed
foldMapOf :: Getter s a -> (a -> r) -> s -> r foldMapOf :: Monoid r => Fold s a -> (a -> r) -> s -> r foldMapOf :: Semigroup r => Fold1 s a -> (a -> r) -> s -> r foldMapOf :: Lens' s a -> (a -> r) -> s -> r foldMapOf :: Iso' s a -> (a -> r) -> s -> r foldMapOf :: Monoid r => Traversal' s a -> (a -> r) -> s -> r foldMapOf :: Semigroup r => Traversal1' s a -> (a -> r) -> s -> r foldMapOf :: Monoid r => Prism' s a -> (a -> r) -> s -> r
foldMapOf :: Getting r s a -> (a -> r) -> s -> r
concatMap ≡ iconcatMap . const iconcatMap ≡ ifoldMap
concatMapOf l ≡ iconcatMapOf l . const iconcatMapOf ≡ ifoldMapOf
iconcatMapOf :: IndexedGetter i s a -> (i -> a -> [r]) -> s -> [r] iconcatMapOf :: IndexedFold i s a -> (i -> a -> [r]) -> s -> [r] iconcatMapOf :: IndexedLens' i s a -> (i -> a -> [r]) -> s -> [r] iconcatMapOf :: IndexedTraversal' i s a -> (i -> a -> [r]) -> s -> [r]