Last active
December 11, 2022 03:03
-
-
Save Grohden/89134a0056e242f3ae3d20090e2e05d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Prelude | |
class Functor | |
def initialize(value) | |
@value = value | |
end | |
# All implementers must satisfy | |
# (a -> b) -> f a -> f b | |
def fmap | |
self.class.new(yield @value) | |
end | |
end | |
# This is technically Either, but we're gonna use it as Result | |
module Result | |
class Success < Functor; end | |
class Failure < Functor | |
def fmap | |
# TODO: explore how we're gonna implement identity (id a -> a) | |
super { |v| v } | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment