Sha256: c5da280c7910b86a89e7f204e1b606d80b6f0701293acd330062ed0451d5453b
Contents?: true
Size: 1.56 KB
Versions: 20
Compression:
Stored size: 1.56 KB
Contents
module Steep module Interface class Block attr_reader :type attr_reader :optional def initialize(type:, optional:) @type = type @optional = optional end def optional? @optional end def required? !optional? end def to_optional self.class.new( type: type, optional: true ) end def ==(other) other.is_a?(self.class) && other.type == type && other.optional == optional end alias eql? == def hash type.hash ^ optional.hash end def closed? type.closed? end def subst(s) ty = type.subst(s) if ty == type self else self.class.new( type: ty, optional: optional ) end end def free_variables() @fvs ||= type.free_variables end def to_s "#{optional? ? "?" : ""}{ #{type.params} -> #{type.return_type} }" end def map_type(&block) self.class.new( type: type.map_type(&block), optional: optional ) end def +(other) optional = self.optional? || other.optional? type = Function.new( params: self.type.params + other.type.params, return_type: AST::Types::Union.build(types: [self.type.return_type, other.type.return_type]), location: nil ) self.class.new( type: type, optional: optional ) end end end end
Version data entries
20 entries across 20 versions & 1 rubygems