1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use std::collections::LinkedList;
use crate::{Iterable, IterableSeq};
impl<T> Iterable for LinkedList<T> {
type C = Self;
type CC<U> = LinkedList<U>;
type F = Self;
type CF<U> = LinkedList<U>;
fn add_one(mut self, a: Self::Item) -> Self::C {
self.push_back(a);
self
}
}
impl<'a, T> Iterable for &'a LinkedList<T> {
type C = LinkedList<&'a T>;
type CC<U> = LinkedList<U>;
type F = LinkedList<&'a T>;
type CF<U> = LinkedList<U>;
}
impl<T> IterableSeq for LinkedList<T> {}
impl<'a, T> IterableSeq for &'a LinkedList<T> {}
delegate_into_iterator!(LinkedList<T>, impl <T>);
delegate_into_iterator!(&'a LinkedList<T>, impl <'a, T: 'a>);
delegate_from_iterator!(LinkedList<T>, T, impl <T>);
delegate_extend!(LinkedList<T>, T, impl <T>);
#[cfg(test)]
mod tests {
use super::*;
fn ll<T>(v: Vec<T>) -> LinkedList<T> {
v.into_iter().collect()
}
#[test]
fn test_c() {
let v = ll(vec![1, 2, 3]);
let res = v.filter(|i| i > &1);
assert_eq!(res, ll(vec![2, 3]));
}
#[test]
fn test_cc() {
let v = ll(vec![1, 2, 3]);
let res = v.map(|i| i.to_string());
assert_eq!(
res,
ll(vec!["1".to_string(), "2".to_string(), "3".to_string()])
);
}
#[test]
fn test_c_r() {
let v = ll(vec![1, 2, 3]);
let res = (&v).filter(|i| i > &&1);
assert_eq!(res, ll(vec![&2, &3]));
}
#[test]
fn test_cc_r() {
let v = ll(vec![1, 2, 3]);
let res = (&v).map(|i| i.to_string());
assert_eq!(
res,
ll(vec!["1".to_string(), "2".to_string(), "3".to_string()])
);
}
}