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

13
LINES

< > BotCompany Repo | #1023031 // optParOr

JavaX fragment (include)

// now also takes a map as single array entry
static <A> A mapMethodLike optParOr(S name, O[] opt, IF0<A> defaultFunction) {
  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(defaultFunction);
  }
  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(defaultFunction);
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1023031
Snippet name: optParOr
Eternal ID of this version: #1023031/3
Text MD5: 6762fc9bdab772fabfdd98a6fffe8eed
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-04-23 13:35:07
Source code size: 473 bytes / 13 lines
Pitched / IR pitched: No / No
Views / Downloads: 298 / 358
Version history: 2 change(s)
Referenced in: [show references]