Skip to content

Instantly share code, notes, and snippets.

@Grohden
Last active December 11, 2022 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Grohden/89134a0056e242f3ae3d20090e2e05d1 to your computer and use it in GitHub Desktop.
Save Grohden/89134a0056e242f3ae3d20090e2e05d1 to your computer and use it in GitHub Desktop.
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