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)

static S repeat(char c, int n) {
  n = Math.max(n, 0);
  char[] chars = new char[n];
  for (int i = 0; i < n; i++)
    chars[i] = c;
  return new String(chars);
}

static <A> L<A> repeat(A a, int n) {
  n = Math.max(n, 0);
  L<A> l = new ArrayList(n);
  for (int i = 0; i < n; i++)
    l.add(a);
  ret l;
}

static <A> L<A> repeat(int n, A a) {
  ret repeat(a, n);
}

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: 648 / 2745
Version history: 4 change(s)
Referenced in: [show references]