114 } |
114 } |
115 } |
115 } |
116 return buf.toList(); |
116 return buf.toList(); |
117 } |
117 } |
118 |
118 |
|
119 /** |
|
120 * Create a new list from the first {@code n} elements of this list |
|
121 */ |
|
122 public List<A> take(int n) { |
|
123 ListBuffer<A> buf = ListBuffer.lb(); |
|
124 int count = 0; |
|
125 for (A el : this) { |
|
126 if (count++ == n) break; |
|
127 buf.append(el); |
|
128 } |
|
129 return buf.toList(); |
|
130 } |
|
131 |
119 /** Construct a list consisting of given element. |
132 /** Construct a list consisting of given element. |
120 */ |
133 */ |
121 public static <A> List<A> of(A x1) { |
134 public static <A> List<A> of(A x1) { |
122 return new List<A>(x1, List.<A>nil()); |
135 return new List<A>(x1, List.<A>nil()); |
123 } |
136 } |