Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 0.28 KB | None | 0 0
  1. template toOption*[T](expr: T; ex: untyped): Option[T] =
  2.   block:
  3.     var res: Option[T]
  4.     try:
  5.       res = some(expr)
  6.     except ex:
  7.       res = none(T)
  8.     res
  9.  
  10. let x = toOption(parseInt("3"), ValueError)  # line(17): cannot instantiate Option got: <int> but expected: <T>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement