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

12
LINES

< > BotCompany Repo | #1024299 // optPar_func

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

Libraryless. Click here for Pure Java version (1629L/11K).

static <A> A mapMethodLike optPar_func(S name, O[] opt, IF0<A> defaultValue) {
  int n = l(opt);
  if (n == 1 && opt[0] instanceof Map) {
    Map map = cast opt[0];
    ret map.containsKey(name) ? (A) map.get(name) : callF(defaultValue);
  }
  if (!even(l(opt))) fail("Odd parameter length");
  for (int i = 0; i < l(opt); i += 2)
    if (eq(opt[i], name))
      ret (A) opt[i+1];
  ret callF(defaultValue);
}

Author comment

Began life as a copy of #1006679

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1024299
Snippet name: optPar_func
Eternal ID of this version: #1024299/4
Text MD5: 87fa4fc970f4e58d9ddd4d506a10f3da
Transpilation MD5: 912adeb66aa16d186dff9df67874ac00
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-07-30 15:24:15
Source code size: 420 bytes / 12 lines
Pitched / IR pitched: No / No
Views / Downloads: 203 / 296
Version history: 3 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)