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

19
LINES

< > BotCompany Repo | #1029592 // OrError - v2 of OKOrError

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

Libraryless. Click here for Pure Java version (2847L/17K).

1  
sclass OrError<A> extends Var<A> {
2  
  O error; // usually a Throwable
3  
  
4  
  *() {}
5  
  *(A value) { super(value); }
6  
  *(bool dummy, O *error) { assertNotNull(error); }
7  
  
8  
  bool ok() { ret error == null; }
9  
  O error() { ret error; }
10  
  
11  
  static <B> OrError<B> ok(B a) { ret new OrError(a); }
12  
  static OrError error(O error) { ret new OrError(true, error); }
13  
  
14  
  toString {
15  
    ret ok()
16  
      ? super.toString()
17  
      : str(error);
18  
  }
19  
}

Author comment

Began life as a copy of #1012580

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1029592
Snippet name: OrError - v2 of OKOrError
Eternal ID of this version: #1029592/6
Text MD5: e0feb3a467b5d0b850ab7a7b5c694a1f
Transpilation MD5: 1a538ab9d1a8762b0d166ee07a91a48a
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-03-18 20:06:52
Source code size: 451 bytes / 19 lines
Pitched / IR pitched: No / No
Views / Downloads: 286 / 571
Version history: 5 change(s)
Referenced in: [show references]