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

36
LINES

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

JavaX fragment (include)

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));
}

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   

Travelled to 12 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1000810
Snippet name: join function + array version
Eternal ID of this version: #1000810/12
Text MD5: a74122294c2cf0ef984d3f7ad2dbaf61
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-02-06 23:18:13
Source code size: 827 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 531 / 10557
Version history: 11 change(s)
Referenced in: [show references]