class Dhall::UnionType

Public Class Methods

decode(record) click to toggle source
# File lib/dhall/binary.rb, line 176
def self.decode(record)
        new(alternatives: Hash[record.map do |k, v|
                [k, v.nil? ? v : Dhall.decode(v)]
        end])
end

Public Instance Methods

==(other) click to toggle source
# File lib/dhall/ast.rb, line 974
def ==(other)
        other.is_a?(UnionType) && alternatives.to_a == other.alternatives.to_a
end
[](k) click to toggle source
# File lib/dhall/ast.rb, line 961
def [](k)
        alternatives.fetch(k)
end
as_json() click to toggle source
# File lib/dhall/ast.rb, line 1012
def as_json
        [11, Hash[alternatives.to_a.map { |k, v| [k, v&.as_json] }.sort]]
end
constructor_types() click to toggle source
# File lib/dhall/ast.rb, line 1002
def constructor_types
        alternatives.each_with_object({}) do |(k, type), ctypes|
                ctypes[k] = if type.nil?
                        self
                else
                        Forall.new(var: k, type: type, body: self)
                end
        end
end
empty?() click to toggle source
# File lib/dhall/ast.rb, line 957
def empty?
        alternatives.empty?
end
eql?(other) click to toggle source
# File lib/dhall/ast.rb, line 978
def eql?(other)
        self == other
end
fetch(k, default=nil) { |: (default || raise)| ... } click to toggle source
Calls superclass method Dhall::Expression#fetch
# File lib/dhall/ast.rb, line 986
def fetch(k, default=nil)
        if alternatives.fetch(k)
                super(k)
        else
                Union.from(self, k, nil)
        end
rescue KeyError
        block_given? ? yield : (default || raise)
end
get_constructor(selector) click to toggle source
# File lib/dhall/ast.rb, line 996
def get_constructor(selector)
        type = alternatives.fetch(selector)
        body = Union.from(self, selector, Variable[selector])
        Function.new(var: selector, type: type, body: body)
end
merge(other, &block) click to toggle source
# File lib/dhall/ast.rb, line 982
def merge(other, &block)
        with(alternatives: alternatives.merge(other.alternatives, &block))
end
normalize() click to toggle source
# File lib/dhall/normalize.rb, line 372
def normalize
        with(alternatives: Hash[super.alternatives.sort])
end
record() click to toggle source
# File lib/dhall/ast.rb, line 970
def record
        alternatives
end
without(*keys) click to toggle source
# File lib/dhall/ast.rb, line 965
def without(*keys)
        keys.map!(&:to_s)
        with(alternatives: alternatives.reject { |k, _| keys.include?(k) })
end