代数的データ型がほしくて
作った.
# 前略 Maybe = algebraic(:nothing, :just, Object) def foo(y) puts match(y) { _(:just) {|x| "Just #{x}" } _ { "Nothing" } } end foo Maybe.new(:just, 42) foo Maybe.new(:nothing)
Just 42 Nothing
Cool!
作った.
# 前略 Maybe = algebraic(:nothing, :just, Object) def foo(y) puts match(y) { _(:just) {|x| "Just #{x}" } _ { "Nothing" } } end foo Maybe.new(:just, 42) foo Maybe.new(:nothing)
Just 42 Nothing
Cool!