diff options
| author | dozens | 2024-05-28 15:04:00 -0600 | 
|---|---|---|
| committer | dozens | 2024-05-28 15:04:00 -0600 | 
| commit | f265d24c0cacb92c7f7db19f364a155d87938184 (patch) | |
| tree | a6e3ce61dee9020b79c8f2d8e3c91b51bc29e959 /lib/either.fnl | |
inits
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 +} | 
