diff options
Diffstat (limited to 'lib/either.fnl')
-rw-r--r-- | lib/either.fnl | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/either.fnl b/lib/either.fnl new file mode 100644 index 0000000..24aafca --- /dev/null +++ b/lib/either.fnl @@ -0,0 +1,20 @@ +(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 +} |