Sha256: e451b9b479b2b6ba09203337fcf0f8eac7286b9ee1ee3b0371f1f2e7cf83581c

Contents?: true

Size: 1.13 KB

Versions: 10

Compression:

Stored size: 1.13 KB

Contents

module Steep
  module AST
    module Types
      class Tuple
        attr_reader :types

        def initialize(types:)
          @types = types
        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(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 map_type(&block)
          Tuple.new(types: types.map(&block))
        end

        def level
          [0] + level_of_children(types)
        end

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
steep-1.9.1 lib/steep/ast/types/tuple.rb
steep-1.9.0 lib/steep/ast/types/tuple.rb
steep-1.9.0.dev.2 lib/steep/ast/types/tuple.rb
steep-1.9.0.dev.1 lib/steep/ast/types/tuple.rb
steep-1.8.3 lib/steep/ast/types/tuple.rb
steep-1.8.2 lib/steep/ast/types/tuple.rb
steep-1.8.1 lib/steep/ast/types/tuple.rb
steep-1.8.0 lib/steep/ast/types/tuple.rb
steep-1.8.0.pre.2 lib/steep/ast/types/tuple.rb
steep-1.8.0.pre.1 lib/steep/ast/types/tuple.rb