[−][src]Function persistent_list::cons
pub fn cons<E: Clone, T: Borrow<List<E>>>(first: E, rest: T) -> List<E>
Construct a List
with a new element at the front of the
current List
.
Alternative to using List::cons
, but enables
writing list construction from front to back.
// Enables this: let list = cons(1, cons(2, List::new())); // Instead of let list = List::new().cons(2).cons(1); // Or let mut list = List::new(); list.push_front(2); list.push_front(1); // Which all result in the equivalent let list = list![1, 2];
Examples
#[macro_use] extern crate persistent_list; assert_eq!( cons(1, cons(2, cons(3, List::new()))), list![1, 2, 3] );