This leads to more consistent formatting across entire Aiken programs. Before that commit, only long expressions would be formatted on a newline, causing non-consistent formatting and additional reading barrier when looking at source code. Programs also now take more vertical space, which is better for more friendly diffing in version control systems (especially git).
32 lines
478 B
Plaintext
32 lines
478 B
Plaintext
pub fn filter(xs: List<a>, f: fn(a) -> Bool) -> List<a> {
|
|
when xs is {
|
|
[] ->
|
|
[]
|
|
[x, ..rest] ->
|
|
if f(x) {
|
|
[x, ..filter(rest, f)]
|
|
} else {
|
|
filter(rest, f)
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn unique(xs: List<a>) -> List<a> {
|
|
when xs is {
|
|
[] ->
|
|
[]
|
|
[x, ..rest] ->
|
|
[x, ..unique(filter(rest, fn(y) { y != x }))]
|
|
}
|
|
}
|
|
|
|
test unique_1() {
|
|
unique([]) == []
|
|
}
|
|
|
|
test unique_2() {
|
|
let xs =
|
|
[1, 2, 3, 1]
|
|
unique(xs) == [1, 2, 3]
|
|
}
|