Put flat_map in ListInternal.aes
This commit is contained in:
parent
02af75aa34
commit
e7d3a5b9f2
@ -102,10 +102,8 @@ namespace List =
|
||||
[] => reverse(acc)
|
||||
h::t => map_(f, t, f(h)::acc)
|
||||
|
||||
function flat_map(f : 'a => list('b), l : list('a)) : list('b) = flat_map_(f, l, [])
|
||||
private function flat_map_(f : 'a => list('b), l : list('a), acc : list('b)) : list('b) = switch(l)
|
||||
[] => reverse(acc)
|
||||
h::t => flat_map_(f, t, reverse(f(h)) ++ acc)
|
||||
function flat_map(f : 'a => list('b), l : list('a)) : list('b) =
|
||||
ListInternal.flat_map(f, l)
|
||||
|
||||
function filter(p : 'a => bool, l : list('a)) : list('a) = filter_(p, l, [])
|
||||
private function filter_(p : 'a => bool, l : list('a), acc : list('a)) : list('a) = switch(l)
|
||||
|
@ -1,9 +1,9 @@
|
||||
namespace ListInternal =
|
||||
|
||||
private function reverse_(xs : list('a), ys : list('a)) : list('a) =
|
||||
// -- Flatmap ----------------------------------------------------------------
|
||||
|
||||
function flat_map(f : 'a => list('b), xs : list('a)) : list('b) =
|
||||
switch(xs)
|
||||
[] => ys
|
||||
x :: xs => reverse_(xs, x :: ys)
|
||||
|
||||
function reverse(xs : list('a)) = reverse_(xs, [])
|
||||
[] => []
|
||||
x :: xs => f(x) ++ flat_map(f, xs)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user