提交 68321b0d 编写于 作者: G Graydon Hoare

Make list.find return an option of different type than the list element.

上级 67d44273
......@@ -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(&T) -> option[T]) f) -> option[T] {
fn find[T,U](&list[T] ls,
(fn(&T) -> option[U]) f) -> option[U] {
alt(ls) {
case (cons[T](?hd, ?tl)) {
alt (f(hd)) {
case (none[T]) {
case (none[U]) {
// FIXME: should use 'be' here, not 'ret'. But parametric tail
// calls currently don't work.
ret find[T](*tl, f);
ret find[T,U](*tl, f);
}
case (some[T](?res)) {
ret some[T](res);
case (some[U](?res)) {
ret some[U](res);
}
}
}
case (nil[T]) {
ret none[T];
ret none[U];
}
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册