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

40
LINES

< > BotCompany Repo | #1000810 - join function + array version

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (3747L/22K).

public static <A> S join(S glue, Iterable<A> strings) {
  if (strings == null) ret "";
  if (strings cast Collection) {
    if (strings.size() == 1) ret str(first(strings));
  }
  new StringBuilder buf;
  Iterator<A> i = strings.iterator();
  if (i.hasNext()) {
    buf.append(i.next());
    while (i.hasNext())
      buf.append(glue).append(i.next());
  }
  ret buf.toString();
}

public static S join(S glue, S... strings) {
  ret join(glue, Arrays.asList(strings));
}

public static S join(S glue, O... strings) {
  ret join(glue, Arrays.asList(strings));
}

static <A> S join(Iterable<A> strings) {
  ret join("", strings);
}

static <A> S join(Iterable<A> strings, S glue) {
  ret join(glue, strings);
}

public static S join(String[] strings) {
  ret join("", strings);
}

ifclass Pair
static S join(S glue, Pair p) {
  ret p == null ? "" : str(p.a) + glue + str(p.b);
}
endif

Author comment

Began life as a copy of #2000507

download  show line numbers  debug dex  old transpilations   

Travelled to 18 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, ekrmjmnbrukm, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1000810
Snippet name: join function + array version
Eternal ID of this version: #1000810/13
Text MD5: f159eb3b145824cd854661538376206f
Transpilation MD5: 8d6d07032dbedecc83f8f2ab5c1029da
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-15 17:04:19
Source code size: 921 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 739 / 12001
Version history: 12 change(s)
Referenced in: #1000265 #1001110 #1001148 #1001370 #1001600 #1001638 #1002427 #1004305 #1006654 #1009467 #1014398 #1015258 #1024219 #1028086 #1030632 #1031138 #3000382