Trying the typeprof playground to see how typeprof would work with an untyped Either class. The output section is left over from the starting example
ruby
# Either Type
# Holds a Left(x) or a Right(y)
class Either
class << self
# Either.Left
# Represents an error in a calculation flow
class Left
def initialize(lval)
@lval = lval
end
def bind
self
end
alias flatmap bind
def map
self
end
def or_else
result = yield @lval
Left.new(result)
end
def left_of?(klass)
@lval.is_a? klass
end
def right_of?(_klass)
false
end
def inspect
"Either::Left<#{@lval.inspect}>"
end
end
# Either.Right
# Represents the result value in a calculation flow
class Right
def initialize(rval)
@rval = rval
end
def bind(&fun)
result = fun.call(@rval)
if result.is_a?(Right) || result.is_a?(Left)
result
else
Right.new(result)
end
end
alias flatmap bind
def map
result = yield @rval
Right.new(result)
end
def or_else
self
end
def left_of?(_klass)
false
end
def right_of?(klass)
@rval.is_a? klass
end
def inspect
"Either::Right<#{@rval.inspect}>"
end
end
def left(value)
Left.new(value)
end
def right(value)
Right.new(value)
end
end
private_class_method :new
end
Issue
Trying the typeprof playground to see how typeprof would work with an untyped Either class. The
output
section is left over from the starting exampleruby
rbs
output