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]

Transpiled version (9674L) is out of date.

public static <A> S join(S glue, Iterable<A> strings) {
  if (strings == null) ret "";
  if (strings cast Collection) {
    if (strings.size() == 1) ret strOrEmpty(first(strings));
  }
  new StringBuilder buf;
  Iterator<A> i = strings.iterator();
  if (i.hasNext()) {
    buf.append(strOrEmpty(i.next()));
    while (i.hasNext())
      buf.append(glue).append(strOrEmpty(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/15
Text MD5: c9bf1e11a119ad1d80626ab26721ba7e
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-11-22 00:51:45
Source code size: 952 bytes / 40 lines
Pitched / IR pitched: No / No
Views / Downloads: 1008 / 12374
Version history: 14 change(s)
Referenced in: #1000265 - Standard Function Adder
#1001110 - x26.java (JavaX)
#1001148 - x27.java (JavaX)
#1001370 - x28.java (JavaX)
#1001600 - x29.java (JavaX)
#1001638 - x30.java (JavaX) - packaged by #1001639
#1002427 - Accellerating 629 (SPIKE)
#1004305 - x31.java (JavaX)
#1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1009467 - join_flex (join with varying separators)
#1014398 - joinChars
#1015258 - join_gen
#1024219 - x30.java (JavaX) backup with JTextArea
#1028086 - joinWithoutFirstAndLast
#1030632 - rjoin function - reverse join
#1031138 - Smarty AI Include
#3000382 - Answer for ferdie (>> t = 1, f = 0)