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

35
LINES

< > BotCompany Repo | #1030670 // chainPlus - append to Chain (to beginning) or to AppendableChain/ReverseChain (to the end)

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

Libraryless. Click here for Pure Java version (3970L/23K).

// Yes the nomenclature is a bit illogical

static <A> Chain<A> chainPlus(Chain<A> chain, A a) {
  ret Chain<A>(a, chain);
}

static <A> Chain<A> chainPlus(Chain<A> chain, A... l) {
  fOr (A a : l)
    chain = chainPlus(chain, a);
  ret chain;
}

static <A> ReverseChain<A> chainPlus(ReverseChain<A> chain, A a) {
  ret ReverseChain<A>(chain, a);
}

static <A> ReverseChain<A> chainPlus(ReverseChain<A> chain, A... l) {
  fOr (A a : l)
    chain = chainPlus(chain, a);
  ret chain;
}

ifclass AppendableChain
static <A> AppendableChain<A> chainPlus(AppendableChain<A> chain, A a) {
  if (chain == null) ret new AppendableChain<A>(a);
  chain.add(a);
  ret chain;
}

static <A> AppendableChain<A> chainPlus(AppendableChain<A> chain, A... l) {
  fOr (A a : l)
    chain = chainPlus(chain, a);
  ret chain;
}
endif

Author comment

Began life as a copy of #1027932

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1030670
Snippet name: chainPlus - append to Chain (to beginning) or to AppendableChain/ReverseChain (to the end)
Eternal ID of this version: #1030670/13
Text MD5: 0f2985590a31ae80c0e89309793f641c
Transpilation MD5: 755d7c71173c64384803ca86a1f1f17b
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-07 13:37:18
Source code size: 847 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 228 / 336
Version history: 12 change(s)
Referenced in: [show references]