Skip to content

Instantly share code, notes, and snippets.

@Rafe
Created April 24, 2018 17:32
Show Gist options
  • Save Rafe/9edb247feb8cb45c46e8d3f82964bee3 to your computer and use it in GitHub Desktop.
Save Rafe/9edb247feb8cb45c46e8d3f82964bee3 to your computer and use it in GitHub Desktop.

Revisions

  1. Rafe created this gist Apr 24, 2018.
    17 changes: 17 additions & 0 deletions Maybe.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    class Maybe
    def initialize(val)
    @val = val
    end

    def fmap
    return self if @val.nil?

    self.class.new(yield @val)
    end

    def inspect
    return 'Nothing' if @val.nil?

    "Just #{@val.inspect}"
    end
    end