Add new acceptance test scenario

```
  Error:
    × Main thread panicked.
    ├─▶ at /Users/ktorz/Documents/Projects/aiken-lang/aiken/crates/project/src/lib.rs:620:22
    ╰─▶ called `Result::unwrap()` on an `Err` value: FreeUnique(Name { text:
        "test_foldr_list_int_data_list_int", unique: Unique(10) })
  ```
This commit is contained in:
KtorZ 2022-12-20 02:22:04 +01:00
parent fccad9e7dd
commit 8bd4fd0cda
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
2 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,2 @@
name = "acceptance_test_026"
version = "0.0.0"

View File

@ -0,0 +1,21 @@
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 concat(left: List<a>, right: List<a>) -> List<a> {
foldr(left, fn(x, xs) { [x, ..xs] }, right)
}
pub fn flat_map(xs: List<a>, f: fn(a) -> List<b>) -> List<b> {
when xs is {
[] -> []
[x, ..rest] -> concat(f(x), flat_map(rest, f))
}
}
test flat_map_2() {
flat_map([1, 2, 3], fn(a) { [a, a] }) == [1, 1, 2, 2, 3, 3]
}