Module
Data.Array.Extra.Last
- Package
- purescript-arrays-extra
- Repository
- flip111/purescript-arrays-extra
Functions that find the last matching element based on a predicate and then do something with the array.
#partitionLast Source
partitionLast :: 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.
partitionLast (== 2) [1,2,3] == Just {yes: 2, no: [1,3]}
#deleteLastWith Source
deleteLastWith :: 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]
#updateLastWith Source
updateLastWith :: 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]
#modifyLastWith Source
modifyLastWith :: 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 aModify 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 aModify 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]