Class: Mal::EitherT

Inherits:
OnlyT
  • Object
show all
Defined in:
lib/mal.rb

Direct Known Subclasses

BoolT, MaybeT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from OnlyT

#&

Constructor Details

#initialize(*types) ⇒ EitherT

Returns a new instance of EitherT.



218
219
220
# File 'lib/mal.rb', line 218

def initialize(*types)
  @types = types
end

Instance Attribute Details

#typesObject (readonly)

Returns the value of attribute types.



217
218
219
# File 'lib/mal.rb', line 217

def types
  @types
end

Instance Method Details

#===(value) ⇒ Object



222
223
224
# File 'lib/mal.rb', line 222

def ===(value)
  @types.any? {|type| type === value }
end

#inspectObject



226
227
228
# File 'lib/mal.rb', line 226

def inspect
  'Either(%s)' % @types.map{|e| e.inspect }.join(', ')
end

#|(another) ⇒ Object



230
231
232
233
234
235
236
237
# File 'lib/mal.rb', line 230

def |(another)
  types_matched = if another.is_a?(EitherT)
    (@types + another.types).uniq
  else
    (@types + [another]).uniq
  end
  EitherT.new(*types_matched)
end