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

16
LINES

< > BotCompany Repo | #1005176 // getSingleton - assert a list/array has exactly one element and get it

JavaX fragment (include)

static <A> A getSingleton(L<A> l) {
  assertEquals(1, l(l));
  ret first(l);
}

static <A> A getSingleton(A[] l) {
  assertEquals(1, l(l));
  ret first(l);
}

ifclass IMultiSet
static <A> A getSingleton(IMultiSet<A> ms) {
  assertEquals(1, l(ms));
  ret first(ms);
}
endif

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1005176
Snippet name: getSingleton - assert a list/array has exactly one element and get it
Eternal ID of this version: #1005176/5
Text MD5: e5882a032889dfb951d496a3e865201b
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2023-02-13 23:23:03
Source code size: 287 bytes / 16 lines
Pitched / IR pitched: No / No
Views / Downloads: 539 / 548
Version history: 4 change(s)
Referenced in: [show references]