fork download
  1.  
  2. type
  3. Maybe* [T] = object {. final .}
  4. case hasValue*: bool
  5. of true: value*: T
  6. else: discard
  7.  
  8.  
  9. proc Just* [T](aValue: T): Maybe[T] {. inline .} =
  10. result = Maybe[T](hasValue: true, value: aValue)
  11.  
  12. template template_Just* [T](aValue: T): Maybe[T] =
  13. Maybe[T](hasValue: true, value: aValue)
  14.  
  15.  
  16. proc Nothing* [T]: Maybe[T] {. inline .} =
  17. result = Maybe[T](hasValue: false)
  18.  
  19.  
  20.  
  21. echo Just[int](1)
  22. echo template_Just[int](1)
  23.  
Success #stdin #stdout 0s 6960KB
stdin
Standard input is empty
stdout
(hasValue: true, value: 1)
(hasValue: true, value: 1)