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

7
LINES

< > BotCompany Repo | #1015727 // singletonOpt - synonym of getSingletonOpt - return single elemtent of list if length == 1 or null otherwise

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

Libraryless. Click here for Pure Java version (7648L/43K).

static <A> A singletonOpt(Collection<A> l) {
  ret l(l) == 1 ? first(l) : null;
}

static <A> A singletonOpt(A[] l) {
  ret l(l) == 1 ? first(l) : null;
}

Author comment

Began life as a copy of #1005177

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1015727
Snippet name: singletonOpt - synonym of getSingletonOpt - return single elemtent of list if length == 1 or null otherwise
Eternal ID of this version: #1015727/4
Text MD5: 900e5dccd8ef05d6aac3429dd0520f0d
Transpilation MD5: 9b605d3822dd6d11326dd1f59eac65b4
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-04-02 18:05:41
Source code size: 160 bytes / 7 lines
Pitched / IR pitched: No / No
Views / Downloads: 314 / 359
Version history: 3 change(s)
Referenced in: [show references]