Create an org heading builder
This commit is contained in:
@@ -2,6 +2,12 @@ import std/sugar
|
||||
import fp/maybe
|
||||
import results
|
||||
|
||||
func last*[T](xs: seq[T]): Maybe[T] =
|
||||
if xs.len == 0:
|
||||
nothing(T)
|
||||
else:
|
||||
just(xs[^1])
|
||||
|
||||
template isSome*(self: Result): bool = self.isOk()
|
||||
template isNone*(self: Result): bool = self.isErr()
|
||||
|
||||
@@ -26,3 +32,6 @@ when isMainModule:
|
||||
echo @[
|
||||
(x: int) => (if x == 2: Just("foo") else: Nothing[string]()),
|
||||
].findMaybeFn(2)
|
||||
|
||||
assert last(@[1,2,3]) == just(3)
|
||||
assert last[int](@[]) == nothing(int)
|
||||
|
||||
Reference in New Issue
Block a user