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

19
LINES

< > BotCompany Repo | #1002222 // repeat - now also for lists

JavaX fragment (include)

1  
static S repeat(char c, int n) {
2  
  n = Math.max(n, 0);
3  
  char[] chars = new char[n];
4  
  for (int i = 0; i < n; i++)
5  
    chars[i] = c;
6  
  return new String(chars);
7  
}
8  
9  
static <A> L<A> repeat(A a, int n) {
10  
  n = Math.max(n, 0);
11  
  L<A> l = new ArrayList(n);
12  
  for (int i = 0; i < n; i++)
13  
    l.add(a);
14  
  ret l;
15  
}
16  
17  
static <A> L<A> repeat(int n, A a) {
18  
  ret repeat(a, n);
19  
}

Author comment

Began life as a copy of #2000505

download  show line numbers  debug dex  old transpilations   

Travelled to 23 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, ekrmjmnbrukm, gwrvuhgaqvyk, ishqpsrjomds, lnbujpyubztb, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, odhhsrjjbcgr, onxytkatvevr, podlckwnjdmb, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, whxojlpjdney, wnsclhtenguj, xrpafgyirdlv

No comments. add comment

Snippet ID: #1002222
Snippet name: repeat - now also for lists
Eternal ID of this version: #1002222/5
Text MD5: bc7453aa5991b30c9c83e433abed23f0
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-12-28 23:56:01
Source code size: 384 bytes / 19 lines
Pitched / IR pitched: No / No
Views / Downloads: 721 / 2825
Version history: 4 change(s)
Referenced in: [show references]