Add new acceptance test scenario (022)
``` thread 'main' has overflowed its stack fatal runtime error: stack overflo ```
This commit is contained in:
parent
44d72c046e
commit
a51808d549
|
@ -0,0 +1,2 @@
|
|||
name = "acceptance_test_022"
|
||||
version = "0.0.0"
|
|
@ -0,0 +1,23 @@
|
|||
pub fn foldr(xs: List<a>, f: fn(a, b) -> b, zero: b) -> b {
|
||||
when xs is {
|
||||
[] -> zero
|
||||
[x, ..rest] -> f(x, foldr(rest, f, zero))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn filter_map(xs: List<a>, f: fn(a) -> Option<b>) -> List<b> {
|
||||
foldr(
|
||||
xs,
|
||||
fn(x, ys) {
|
||||
when f(x) is {
|
||||
None -> ys
|
||||
Some(y) -> [y, ..ys]
|
||||
}
|
||||
},
|
||||
[],
|
||||
)
|
||||
}
|
||||
|
||||
test filter_map_1() {
|
||||
filter_map([], fn(_) { Some(42) }) == []
|
||||
}
|
Loading…
Reference in New Issue