Class: Dhall::UnionType
- Inherits:
-
Expression
show all
- Defined in:
- lib/dhall/ast.rb,
lib/dhall/binary.rb,
lib/dhall/normalize.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Expression
#&, #*, #+, #as_dhall, #cache_key, #call, #concat, #deep_merge, #deep_merge_type, #dhall_eq, #digest, #fusion, #resolve, #shift, #slice, #substitute, #to_binary, #to_cbor, #to_proc, #to_s, #|
Class Method Details
.decode(record) ⇒ Object
176
177
178
179
180
|
# 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
|
Instance Method Details
#==(other) ⇒ Object
925
926
927
|
# File 'lib/dhall/ast.rb', line 925
def ==(other)
other.is_a?(UnionType) && alternatives.to_a == other.alternatives.to_a
end
|
#[](k) ⇒ Object
912
913
914
|
# File 'lib/dhall/ast.rb', line 912
def [](k)
alternatives.fetch(k)
end
|
#as_json ⇒ Object
963
964
965
|
# File 'lib/dhall/ast.rb', line 963
def as_json
[11, Hash[alternatives.to_a.map { |k, v| [k, v&.as_json] }.sort]]
end
|
#constructor_types ⇒ Object
953
954
955
956
957
958
959
960
961
|
# File 'lib/dhall/ast.rb', line 953
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? ⇒ Boolean
908
909
910
|
# File 'lib/dhall/ast.rb', line 908
def empty?
alternatives.empty?
end
|
#eql?(other) ⇒ Boolean
929
930
931
|
# File 'lib/dhall/ast.rb', line 929
def eql?(other)
self == other
end
|
#fetch(k, default = nil) ⇒ Object
937
938
939
940
941
942
943
944
945
|
# File 'lib/dhall/ast.rb', line 937
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) ⇒ Object
947
948
949
950
951
|
# File 'lib/dhall/ast.rb', line 947
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) ⇒ Object
933
934
935
|
# File 'lib/dhall/ast.rb', line 933
def merge(other, &block)
with(alternatives: alternatives.merge(other.alternatives, &block))
end
|
#normalize ⇒ Object
356
357
358
|
# File 'lib/dhall/normalize.rb', line 356
def normalize
with(alternatives: Hash[super.alternatives.sort])
end
|
#record ⇒ Object
921
922
923
|
# File 'lib/dhall/ast.rb', line 921
def record
alternatives
end
|
#without(*keys) ⇒ Object
916
917
918
919
|
# File 'lib/dhall/ast.rb', line 916
def without(*keys)
keys.map!(&:to_s)
with(alternatives: alternatives.reject { |k, _| keys.include?(k) })
end
|