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

26
LINES

< > BotCompany Repo | #1030632 // rjoin function - reverse join

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

Libraryless. Click here for Pure Java version (2773L/16K).

static <A> S rjoin(S glue default "", 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 = reversed(strings).iterator();
  if (i.hasNext()) {
    buf.append(i.next());
    while (i.hasNext())
      buf.append(glue).append(i.next());
  }
  ret buf.toString();
}

sS rjoin(S glue, S... strings) {
  ret join(glue, asVirtualReversedList(strings));
}

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

sS rjoin(S[] strings) {
  ret rjoin("", strings);
}

Author comment

Began life as a copy of #1000810

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030632
Snippet name: rjoin function - reverse join
Eternal ID of this version: #1030632/1
Text MD5: 24a1a445f695bed7fc3122a8c87e9135
Transpilation MD5: 539a18eb092f769d9f0d60c303ad103e
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-02-09 10:05:51
Source code size: 640 bytes / 26 lines
Pitched / IR pitched: No / No
Views / Downloads: 105 / 156
Referenced in: [show references]