Libraryless. Click here for Pure Java version (5106L/28K).
1 | static <A> L<A> cloneTakeFirst(Cl<A> l, int n) { |
2 | n = min(n, l(l)); |
3 | L<A> out = emptyList(n); |
4 | if (n != 0) |
5 | for (A a : l) { |
6 | out.add(a); |
7 | if (l(out) >= n) |
8 | break; |
9 | } |
10 | ret out; |
11 | } |
12 | |
13 | static <A> L<A> cloneTakeFirst(int n, Cl<A> l) { |
14 | ret cloneTakeFirst(l, n); |
15 | } |
16 | |
17 | static <A> L<A> cloneTakeFirst(L<A> l, int n) { |
18 | ret l(l) <= n ? l : cloneSubList(l, 0, n); |
19 | } |
20 | |
21 | static <A> L<A> cloneTakeFirst(int n, L<A> l) { |
22 | ret cloneTakeFirst(l, n); |
23 | } |
Began life as a copy of #1007549
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1025353 |
Snippet name: | cloneTakeFirst function - take first, but always return new list |
Eternal ID of this version: | #1025353/4 |
Text MD5: | 30f30d1ba451140af7ca8d81841546db |
Transpilation MD5: | d86d3062f8e0642586afcdba1997729b |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-03-07 22:26:30 |
Source code size: | 481 bytes / 23 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 245 / 323 |
Version history: | 3 change(s) |
Referenced in: | [show references] |