Libraryless. Click here for Pure Java version (5106L/28K).
static <A> L<A> cloneTakeFirst(Cl<A> l, int n) { n = min(n, l(l)); L<A> out = emptyList(n); if (n != 0) for (A a : l) { out.add(a); if (l(out) >= n) break; } ret out; } static <A> L<A> cloneTakeFirst(int n, Cl<A> l) { ret cloneTakeFirst(l, n); } static <A> L<A> cloneTakeFirst(L<A> l, int n) { ret l(l) <= n ? l : cloneSubList(l, 0, n); } static <A> L<A> cloneTakeFirst(int n, L<A> l) { ret cloneTakeFirst(l, n); }
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: | 244 / 321 |
Version history: | 3 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1027261 - takeFirst_cloneIfDifferent - take first, return new list unless list isn't cut at all |