Make list.find return an option of different type than the list element.
This commit is contained in:
parent
67d4427345
commit
68321b0de8
1 changed files with 7 additions and 7 deletions
|
@ -26,23 +26,23 @@ fn foldl[T,U](&list[T] ls, U u, fn(&T t, U u) -> U f) -> U {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find[T](&list[T] ls,
|
fn find[T,U](&list[T] ls,
|
||||||
(fn(&T) -> option[T]) f) -> option[T] {
|
(fn(&T) -> option[U]) f) -> option[U] {
|
||||||
alt(ls) {
|
alt(ls) {
|
||||||
case (cons[T](?hd, ?tl)) {
|
case (cons[T](?hd, ?tl)) {
|
||||||
alt (f(hd)) {
|
alt (f(hd)) {
|
||||||
case (none[T]) {
|
case (none[U]) {
|
||||||
// FIXME: should use 'be' here, not 'ret'. But parametric tail
|
// FIXME: should use 'be' here, not 'ret'. But parametric tail
|
||||||
// calls currently don't work.
|
// calls currently don't work.
|
||||||
ret find[T](*tl, f);
|
ret find[T,U](*tl, f);
|
||||||
}
|
}
|
||||||
case (some[T](?res)) {
|
case (some[U](?res)) {
|
||||||
ret some[T](res);
|
ret some[U](res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case (nil[T]) {
|
case (nil[T]) {
|
||||||
ret none[T];
|
ret none[U];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue