Module
Data.Array.Extra.First
- Package
- purescript-arrays-extra
- Repository
- flip111/purescript-arrays-extra
Functions that find the first matching element based on a predicate and then do something with the array.
#partitionFirst Source
partitionFirst :: forall a. (a -> Boolean) -> Array a -> Maybe { no :: Array a, yes :: a }
Find an element by a predicate and return it together with the array without the element.
partitionFirst (== 2) [1,2,3] == Just {yes: 2, no: [1,3]}
#deleteFirstWith Source
deleteFirstWith :: forall a. (a -> Boolean) -> Array a -> Maybe (Array a)
Find an element by a predicate and return an array without that element when it was found.
deleteWith (== 2) [1,2,3] == Just [1,3]
#updateFirstWith Source
updateFirstWith :: forall a. (a -> Boolean) -> a -> Array a -> Maybe (Array a)
Find an element by a predicate and return an array with the updated element when it was found
updateWith (== 2) 4 [1,2,3] == Just [1,4,3]
#modifyFirstWith Source
modifyFirstWith :: forall a. (a -> Boolean) -> (a -> a) -> Array a -> Maybe (Array a)
Find an element by a predicate and return an array with the updated element when it was found
modifyWith (== 2) (* 3) [1,2,3] == Just [1,6,3]
#modifyOrSnoc Source
modifyOrSnoc :: forall a. (a -> Boolean) -> (a -> a) -> Array a -> a -> Array a
Modify an element when it was found by the predicate or append a new element to the end of the array.
modifyOrSnoc (== 2) (* 3) [1,2,3] 11 == Just [1,6,3]
modifyOrSnoc (== 4) (* 3) [1,2,3] 11 == Just [1,2,3,11]
#modifyOrCons Source
modifyOrCons :: forall a. (a -> Boolean) -> (a -> a) -> a -> Array a -> Array a
Modify an element when it was found by the predicate or push a new element to the front of the array.
modifyOrCons (== 2) (* 3) 11 [1,2,3] == Just [1,6,3]
modifyOrCons (== 4) (* 3) 11 [1,2,3] == Just [11,1,2,3]