prelude.ls is a functionally oriented utility library - powerful and flexible, almost all of functions are curried. It is written in, and is the recommended base library for, http://livescript.net
mapAccumL :: (a -> b -> (a, c)) -> a -> [b] -> (a, [c])
mapAccumR :: (a -> b -> (a, c)) -> a -> [b] -> (a, [c])
from haskell Data.List
They afford to map a list with auxiliary value, kind of hybrid of map and fold, applies a function to each element of a structure, passing an accumulating parameter from left to right or vice versa, and returning a final value of this accumulator together with the new structure.
Possible implementation:
mapAccumL = (next, start, bs) -->
| empty bs => [start, []]
| otherwise =>
scanned = tail <| scanl (([a, c], b) -> next a, b), [start, null] <| bs
[head <| last scanned; map last <| scanned]
I suggest to add the functions:
from haskell
Data.List
They afford to map a list with auxiliary value, kind of hybrid ofmap
andfold
, applies a function to each element of a structure, passing an accumulating parameter from left to right or vice versa, and returning a final value of this accumulator together with the new structure. Possible implementation: