blob: 51d01355a9bae8fbad0181df5ba89131e855144e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
type
TMaybe[T] = object
case empty: Bool
of False: value: T
else: nil
proc Just*[T](val: T): TMaybe[T] =
result.empty = False
result.value = val
proc Nothing[T](): TMaybe[T] =
result.empty = True
proc safeReadLine(): TMaybe[string] =
var r = stdin.readLine()
if r == "": return Nothing[string]()
else: return Just(r)
when isMainModule:
var Test = Just("Test")
echo(Test.value)
var mSomething = safeReadLine()
echo(mSomething.value)
|