Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

14
LINES

< > BotCompany Repo | #1022354 // takeFirst_clone function (take first n elements of a list, always make a new list)

JavaX fragment (include)

1  
static <A> L<A> takeFirst_clone(L<A> l, int n) {
2  
  ret cloneSubList(l, 0, n);
3  
}
4  
5  
static <A> L<A> takeFirst_clone(int n, L<A> l) {
6  
  ret takeFirst_clone(l, n);
7  
}
8  
9  
static <A> L<A> takeFirst_clone(int n, Iterable<A> i) {
10  
  L l = new L;
11  
  Iterator<A> it = i.iterator();
12  
  repeat n { if (it.hasNext()) l.add(it.next()); else break; }
13  
  ret l;
14  
}

Author comment

Began life as a copy of #1007549

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1022354
Snippet name: takeFirst_clone function (take first n elements of a list, always make a new list)
Eternal ID of this version: #1022354/3
Text MD5: 776f0fe8882e3688ea61f36a57a557c9
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-03-15 09:13:25
Source code size: 354 bytes / 14 lines
Pitched / IR pitched: No / No
Views / Downloads: 182 / 218
Version history: 2 change(s)
Referenced in: [show references]