diff --git a/examples/acceptance_tests/034/aiken.lock b/examples/acceptance_tests/034/aiken.lock new file mode 100644 index 00000000..3a78b1e7 --- /dev/null +++ b/examples/acceptance_tests/034/aiken.lock @@ -0,0 +1,5 @@ +# This file was generated by Aiken +# You typically do not need to edit this file + +requirements = [] +packages = [] diff --git a/examples/acceptance_tests/034/aiken.toml b/examples/acceptance_tests/034/aiken.toml new file mode 100644 index 00000000..a81d1f44 --- /dev/null +++ b/examples/acceptance_tests/034/aiken.toml @@ -0,0 +1,2 @@ +name = "aiken-lang/acceptance_test_034" +version = "0.0.0" diff --git a/examples/acceptance_tests/034/lib/tests.ak b/examples/acceptance_tests/034/lib/tests.ak new file mode 100644 index 00000000..a215135f --- /dev/null +++ b/examples/acceptance_tests/034/lib/tests.ak @@ -0,0 +1,18 @@ +pub fn foldr(self: List, with: fn(a, b) -> b, zero: b) -> b { + when self is { + [] -> zero + [x, ..xs] -> with(x, foldr(xs, with, zero)) + } +} + +pub fn flat_map(self: List, with: fn(a) -> List) -> List { + foldr(self, fn(x, xs) { concat(with(x), xs) }, []) +} + +test flat_map_1() { + flat_map([], fn(a) { [a] }) == [] +} + +test flat_map_2() { + flat_map([1, 2, 3], fn(a) { [a, a] }) == [1, 1, 2, 2, 3, 3] +}