Module

Data.Traversable.Extra

Package
purescript-foldable-traversable-extra
Repository
flip111/purescript-foldable-traversable-extra

#mapAll Source

mapAll :: forall a b f. Traversable f => (a -> Maybe b) -> f a -> Maybe (f b)

Map an array conditionally, only return the array when all elements were mapped. Note that this function is an alias for traverse. This is specific behavior for the implementation of <*> for Applicative Maybe.

Hint: mapAny can be found in Data.Foldable.Extra

mapAll (\x -> if x == 2 then Just 99 else Nothing) [1,2,3] == Nothing
mapAll (\x -> Just (x * 2)) [1,2,3] == Just [2,4,6]

#mapModify Source

mapModify :: forall a f. Traversable f => (a -> { new :: a, old :: a }) -> f a -> Tuple (Array a) (f a)

Like map but extracts the replaced values into an array. Allows modification of the replaced values as well.

#mapMaybeWrite Source

mapMaybeWrite :: forall a f. Traversable f => (a -> Maybe a) -> f a -> Tuple (Array a) (f a)

Conditionally map the function over the the functor. Returns a Tuple with the new functor and the replaced values.

#mapMaybeWriteModify Source

mapMaybeWriteModify :: forall a f. Traversable f => (a -> Maybe { new :: a, old :: a }) -> f a -> Tuple (Array a) (f a)

Same as mapMaybeWrite but allows modification of replaced values before returning them. Useful when the old and new values need to be linked to each other.