Implemented list::is_empty() based on Container trait
This commit is contained in:
parent
e589fcffcc
commit
a14d72d49e
2 changed files with 12 additions and 17 deletions
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
extern crate collections;
|
||||
|
||||
use collections::list::{List, Cons, Nil, head, is_empty};
|
||||
use collections::list::{List, Cons, Nil, head};
|
||||
|
||||
fn pure_length_go<T:Clone>(ls: @List<T>, acc: uint) -> uint {
|
||||
match *ls { Nil => { acc } Cons(_, tl) => { pure_length_go(tl, acc + 1u) } }
|
||||
|
|
@ -25,7 +25,7 @@ fn pure_length<T:Clone>(ls: @List<T>) -> uint { pure_length_go(ls, 0u) }
|
|||
fn nonempty_list<T:Clone>(ls: @List<T>) -> bool { pure_length(ls) > 0u }
|
||||
|
||||
fn safe_head<T:Clone>(ls: @List<T>) -> T {
|
||||
assert!(!is_empty(ls));
|
||||
assert!(!ls.is_empty());
|
||||
return head(ls);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue