// Main package file for your library code.
// Put public APIs and shared helpers here.
// Keep blocks small and focused for easy refactors.
pub(all) struct Student {
id : String
score : Double
}
pub(all) enum ExamResult {
Pass
Fail
}derive(Show)
pub fn is_qualified(student : Student, criteria : Double) -> ExamResult {
if student.score >= criteria {
Pass
} else {
Fail
}
}
pub fn count_qualified_students(
students : Array[Student],
is_qualified : (Student) -> ExamResult
) -> Int {
students.iter().filter(fn(student) { is_qualified(student) == Pass }).count()
}
pub fn assert_eq[A : Eq + Show](value : A, other : A) -> Unit {
if value != other {
abort("assert_eq failed: \{value} != \{other}")
}
}
pub impl Eq for ExamResult with equal(self, other) {
match (self, other) {
(Pass, Pass) | (Fail, Fail) => true
_ => false
}
}