Merge pull request #351 from aiken-lang/acceptance-test-054-pattern-match-on-list

Add new acceptance test scenario: 056
This commit is contained in:
Matthias Benkort
2023-02-16 10:01:56 +01:00
committed by GitHub
6 changed files with 96 additions and 8 deletions

View File

@@ -0,0 +1,5 @@
# This file was generated by Aiken
# You typically do not need to edit this file
requirements = []
packages = []

View File

@@ -0,0 +1,3 @@
name = "aiken-lang/acceptance_test_056"
version = "0.0.0"
dependencies = []

View File

@@ -0,0 +1,24 @@
// Could possibly be forbidden by the parser instead if we have no intent to support that.
pub fn choice(self: List<Option<a>>) -> Option<a> {
when self is {
[] -> None
[Some(_) as result, ..] -> result
[None, ..others] -> choice(others)
}
}
test choice_1() {
choice([Some(14), Some(42)]) == Some(14)
}
test choice_2() {
choice([]) == None
}
test choice_3() {
choice([None]) == None
}
test choice_4() {
choice([None, Some(42)]) == Some(42)
}

View File

@@ -0,0 +1,23 @@
pub fn choice(self: List<Option<a>>) -> Option<a> {
when self is {
[] -> None
[Some(x), ..] -> Some(x)
[None, ..others] -> choice(others)
}
}
test choice_1() {
choice([Some(14), Some(42)]) == Some(14)
}
test choice_2() {
choice([]) == None
}
test choice_3() {
choice([None]) == None
}
test choice_4() {
choice([None, Some(42)]) == Some(42)
}

View File

@@ -0,0 +1,23 @@
pub fn choice(self: List<Option<a>>) -> Option<a> {
when self is {
[] -> None
[None, ..others] -> choice(others)
[result, ..] -> result
}
}
test choice_1() {
choice([Some(14), Some(42)]) == Some(14)
}
test choice_2() {
choice([]) == None
}
test choice_3() {
choice([None]) == None
}
test choice_4() {
choice([None, Some(42)]) == Some(42)
}