Module

Data.Semigroup.Foldable.Extra

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

#mapAny Source

mapAny :: forall a f. Traversable1 f => (a -> Maybe a) -> f a -> Maybe (f a)

Map an array conditionally, only return the array when at least one element was mapped. Elements that are not mapped will keep the old value.

Hint: mapAll can be found in Data.Semigroup.Traversable.Extra

mapAny (\_ -> Nothing) (Data.Array.NonEmpty.cons' 1 [2, 3]) == Nothing
mapAny (\x -> if x == 2 then Just 99 else Nothing) (Data.Array.NonEmpty.cons' 1 [2, 3]) == Data.Array.NonEmpty.fromArray [1,99,3]

Not that in the second example the Just is implicit.