9mm/lib/either.fnl

21 lines
367 B
Plaintext
Raw Normal View History

2024-05-28 21:04:00 +00:00
(local Either {})
(local Left {})
(local Right {})
(setmetatable Right Either)
(setmetatable Left Either)
(fn Either.new [self x]
(local obj { :value (or x {}) })
(tset self "__index" self)
(setmetatable obj self))
(fn Either.of [x] (Right:new x))
(fn Right.map [self f] (Either.of (f self.value)))
(fn Left.map [self f] self)
{
: Either
: Left
: Right
}