Sha256: 6feadce9040e1d8462b3891ba7b627f4bd9e37d03b32113522a2336ba57edc55

Contents?: true

Size: 1.18 KB

Versions: 26

Compression:

Stored size: 1.18 KB

Contents

module Steep
  module AST
    module Types
      class Tuple
        attr_reader :types
        attr_reader :location

        def initialize(types:, location: nil)
          @types = types
          @location = location
        end

        def ==(other)
          other.is_a?(Tuple) &&
            other.types == types
        end

        def hash
          self.class.hash ^ types.hash
        end

        alias eql? ==

        def subst(s)
          self.class.new(location: location,
                         types: types.map {|ty| ty.subst(s) })
        end

        def to_s
          "[#{types.join(", ")}]"
        end

        def free_variables()
          @fvs ||= each_child.with_object(Set[]) do |type, set| #$ Set[variable]
            set.merge(type.free_variables)
          end
        end

        include Helper::ChildrenLevel

        def each_child(&block)
          if block
            types.each(&block)
          else
            types.each
          end
        end

        def level
          [0] + level_of_children(types)
        end

        def with_location(new_location)
          self.class.new(types: types, location: new_location)
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
steep-1.7.0.dev.2 lib/steep/ast/types/tuple.rb
steep-1.7.0.dev.1 lib/steep/ast/types/tuple.rb
steep-1.6.0 lib/steep/ast/types/tuple.rb
steep-1.6.0.pre.4 lib/steep/ast/types/tuple.rb
steep-1.6.0.pre.3 lib/steep/ast/types/tuple.rb
steep-1.6.0.pre.2 lib/steep/ast/types/tuple.rb
steep-1.6.0.pre.1 lib/steep/ast/types/tuple.rb
steep-1.5.3 lib/steep/ast/types/tuple.rb
steep-1.5.2 lib/steep/ast/types/tuple.rb
steep-1.5.1 lib/steep/ast/types/tuple.rb
steep-1.5.0 lib/steep/ast/types/tuple.rb
steep-1.5.0.pre.6 lib/steep/ast/types/tuple.rb
steep-1.5.0.pre.5 lib/steep/ast/types/tuple.rb
steep-1.5.0.pre.4 lib/steep/ast/types/tuple.rb
steep-1.5.0.pre.3 lib/steep/ast/types/tuple.rb
steep-1.5.0.pre.2 lib/steep/ast/types/tuple.rb
steep-1.5.0.pre.1 lib/steep/ast/types/tuple.rb
steep-1.4.0 lib/steep/ast/types/tuple.rb
steep-1.4.0.dev.5 lib/steep/ast/types/tuple.rb
steep-1.4.0.dev.4 lib/steep/ast/types/tuple.rb