diff options
| author | Graydon Hoare <[email protected]> | 2010-10-18 16:02:59 -0700 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2010-10-18 16:02:59 -0700 |
| commit | 68321b0de87cd40664f490a53a225e4058dd1739 (patch) | |
| tree | 9eecadef88ec992bb57dd1225c78b0d488f22f05 /src/lib/list.rs | |
| parent | Begin sketching name lookup in rustc. (diff) | |
| download | rust-68321b0de87cd40664f490a53a225e4058dd1739.tar.xz rust-68321b0de87cd40664f490a53a225e4058dd1739.zip | |
Make list.find return an option of different type than the list element.
Diffstat (limited to 'src/lib/list.rs')
| -rw-r--r-- | src/lib/list.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/lib/list.rs b/src/lib/list.rs index 60c23a9e..7b861315 100644 --- a/src/lib/list.rs +++ b/src/lib/list.rs @@ -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]; } } } |