Function im::list::cons
[−]
[src]
pub fn cons<A>(car: A, cdr: &List<A>) -> List<A>
Prepend a value to a list.
Constructs a list with the value car
prepended to the
front of the list cdr
.
This is just a shorthand for list.cons(item)
, but I find
it much easier to read cons(1, &cons(2, &List::empty()))
than List::empty().cons(2).cons(1)
, given that the resulting
list will be [1, 2]
.
Examples
assert_eq!( cons(1, &cons(2, &cons(3, &List::empty()))), list![1, 2, 3] );