Well in Ocaml you can do this at compile-time :
let handle item = match item with
| 1 -> "Do this";
| 2 -> "Do that";
| n -> "Do Nothing";
;;
Is there a way to realize it at runtime ? Like some kind of chain of responsibility pattern ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, there is such a pattern.
Let’s assume that you’re dealing with a function that must accept an integer and return a string, and that by default it will return
"Do nothing"for every integer :If you wish to say that
"Do this"should be returned when the argument is 1, you can do: