21 lines
367 B
Plaintext
21 lines
367 B
Plaintext
|
(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
|
||
|
}
|