2046:1fe358ea75ff | 2047:5f915a0c9615 |
---|---|
95 } | 95 } |
96 return res.reverse(); | 96 return res.reverse(); |
97 } | 97 } |
98 | 98 |
99 public List<A> intersect(List<A> that) { | 99 public List<A> intersect(List<A> that) { |
100 ListBuffer<A> buf = ListBuffer.lb(); | 100 ListBuffer<A> buf = new ListBuffer<>(); |
101 for (A el : this) { | 101 for (A el : this) { |
102 if (that.contains(el)) { | 102 if (that.contains(el)) { |
103 buf.append(el); | 103 buf.append(el); |
104 } | 104 } |
105 } | 105 } |
106 return buf.toList(); | 106 return buf.toList(); |
107 } | 107 } |
108 | 108 |
109 public List<A> diff(List<A> that) { | 109 public List<A> diff(List<A> that) { |
110 ListBuffer<A> buf = ListBuffer.lb(); | 110 ListBuffer<A> buf = new ListBuffer<>(); |
111 for (A el : this) { | 111 for (A el : this) { |
112 if (!that.contains(el)) { | 112 if (!that.contains(el)) { |
113 buf.append(el); | 113 buf.append(el); |
114 } | 114 } |
115 } | 115 } |
118 | 118 |
119 /** | 119 /** |
120 * Create a new list from the first {@code n} elements of this list | 120 * Create a new list from the first {@code n} elements of this list |
121 */ | 121 */ |
122 public List<A> take(int n) { | 122 public List<A> take(int n) { |
123 ListBuffer<A> buf = ListBuffer.lb(); | 123 ListBuffer<A> buf = new ListBuffer<>(); |
124 int count = 0; | 124 int count = 0; |
125 for (A el : this) { | 125 for (A el : this) { |
126 if (count++ == n) break; | 126 if (count++ == n) break; |
127 buf.append(el); | 127 buf.append(el); |
128 } | 128 } |
165 xs = new List<A>(array[i], xs); | 165 xs = new List<A>(array[i], xs); |
166 return xs; | 166 return xs; |
167 } | 167 } |
168 | 168 |
169 public static <A> List<A> from(Iterable<? extends A> coll) { | 169 public static <A> List<A> from(Iterable<? extends A> coll) { |
170 ListBuffer<A> xs = ListBuffer.lb(); | 170 ListBuffer<A> xs = new ListBuffer<>(); |
171 for (A a : coll) { | 171 for (A a : coll) { |
172 xs.append(a); | 172 xs.append(a); |
173 } | 173 } |
174 return xs.toList(); | 174 return xs.toList(); |
175 } | 175 } |