t9286.nim 404 B

1234567891011121314151617181920212223
  1. discard """
  2. action: run
  3. """
  4. import options
  5. type Foo = ref object
  6. i: int
  7. proc next(foo: Foo): Option[Foo] =
  8. try: doAssert(foo.i == 0)
  9. except: return # 2º: none
  10. return some(foo) # 1º: some
  11. proc test =
  12. let foo = Foo()
  13. var opt = next(foo) # 1º Some
  14. while isSome(opt) and foo.i < 10:
  15. inc(foo.i)
  16. opt = next(foo) # 2º None
  17. doAssert foo.i == 1, $foo.i
  18. test()