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

17
LINES

< > BotCompany Repo | #1009173 - Either - union type

JavaX fragment (include)

sclass Either<A, B> {
  byte which;
  O value;
  
  *() {}
  *(int which, O *value) { this.which = (byte) which; }
  
  bool isA() { ret which == 1; }
  bool isB() { ret which == 2; }
  
  A a() { if (which != 1) _failMe(); ret (A) value; }
  B b() { if (which != 2) _failMe(); ret (B) value; }
  
  void _failMe {
    fail("Either object is of wrong type: " + shortClassName(value));
  }
}

Author comment

Began life as a copy of #1009167

download  show line numbers  debug dex   

Travelled to 10 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1009173
Snippet name: Either - union type
Eternal ID of this version: #1009173/1
Text MD5: a27b439402f722e882320f475b83eef7
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-07-12 13:28:44
Source code size: 406 bytes / 17 lines
Pitched / IR pitched: No / No
Views / Downloads: 335 / 1178
Referenced in: [show references]

Formerly at http://tinybrain.de/1009173 & http://1009173.tinybrain.de