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

24
LINES

< > BotCompany Repo | #1027545 // WaitForAnswer_YesNo

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

Libraryless. Click here for Pure Java version (2824L/18K).

sclass WaitForAnswer_YesNo {
  S question;
  
  pswappable S answer(S s) {
    if (isCancelCommand(s)) ret cancel();
    if (isYes(s)) {
      cancelSilently();
      ret processAnswer(true);
    }
    if "no" {
      cancelSilently();
      ret processAnswer(false);
    }
    ret otherInput(s);
  }
  
  pswappable bool isYes(S s) { ret main isYes(s); }
  pswappable bool isNo(S s) { ret main isNo(s); }
  pswappable S otherInput(S s) { ret "I don't understand. Yes or no?"; }
  pswappable S processAnswer(bool yes) { ret "You said " + yesNo_short(yes); }
  pswappable bool isCancelCommand(S s) { ret match("cancel", s); }
  pswappable void cancelSilently() { print("Cancelling"); }
  pswappable S cancel() { cancelSilently(); ret "Action cancelled"; }
}

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: #1027545
Snippet name: WaitForAnswer_YesNo
Eternal ID of this version: #1027545/5
Text MD5: f9a2b5fa4d6c9258d79bc9bb24f9969d
Transpilation MD5: 6e995c20ac0f362875e0600339e1ef6b
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-23 18:57:55
Source code size: 779 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 245 / 605
Version history: 4 change(s)
Referenced in: [show references]