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).

1  
static <A> S rjoin(S glue default "", Iterable<A> strings) {
2  
  if (strings == null) ret "";
3  
  if (strings cast Collection) {
4  
    if (strings.size() == 1) ret str(first(strings));
5  
  }
6  
  new StringBuilder buf;
7  
  Iterator<A> i = reversed(strings).iterator();
8  
  if (i.hasNext()) {
9  
    buf.append(i.next());
10  
    while (i.hasNext())
11  
      buf.append(glue).append(i.next());
12  
  }
13  
  ret buf.toString();
14  
}
15  
16  
sS rjoin(S glue, S... strings) {
17  
  ret join(glue, asVirtualReversedList(strings));
18  
}
19  
20  
static <A> S rjoin(Iterable<A> strings, S glue) {
21  
  ret rjoin(glue, strings);
22  
}
23  
24  
sS rjoin(S[] strings) {
25  
  ret rjoin("", strings);
26  
}

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: 184 / 258
Referenced in: [show references]