From f265d24c0cacb92c7f7db19f364a155d87938184 Mon Sep 17 00:00:00 2001 From: dozens Date: Tue, 28 May 2024 15:04:00 -0600 Subject: inits --- lib/either.fnl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lib/either.fnl (limited to 'lib/either.fnl') 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 +} -- cgit 1.4.1-2-gfad0