reasonml-community / belt

MIT License
49 stars 1 forks source link

List.reduceWhile / List.reduceUntil #34

Open bram209 opened 5 years ago

bram209 commented 5 years ago

Would love a reduceUntil / reduceWhile method. What do you guys think?

Example:

type t('a, 'b) =
  | Continue('a)
  | Stop('b);

let rec reduceUntil = (list, acc, f) => 
 switch (list) {
  | [] => acc
  | [h, ...t] => 
    switch(f(acc, h)) {
    | Stop(result) => result
    | Continue(acc) => reduce(t, acc, f)
  };