Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.35 KB | None | 0 0
  1. class Maybe
  2.     ...
  3. end
  4.  
  5. class Left
  6.     ...
  7. end
  8.  
  9. class Right
  10.     ...
  11. end
  12.  
  13. def more_than_zero?(num)
  14.     if num.kind_of?(Integer)
  15.         Right[num > 0 ? true : false]
  16.     else
  17.         Left['only integers allowed here']
  18.     end
  19. end
  20.  
  21. result = more_than_zero(3)
  22.  
  23. Maybe[result].
  24.     on(Left,  -> (res) { p "Error: #{res}" }).
  25.     on(Right, -> (res) { p "Result: #{res}"}))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement