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_cbor, #to_proc, #|
Class Method Details
.decode(record) ⇒ Object
152
153
154
155
156
|
# File 'lib/dhall/binary.rb', line 152
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
760
761
762
|
# File 'lib/dhall/ast.rb', line 760
def ==(other)
other.is_a?(UnionType) && alternatives.to_a == other.alternatives.to_a
end
|
#as_json ⇒ Object
800
801
802
|
# File 'lib/dhall/ast.rb', line 800
def as_json
[11, Hash[alternatives.to_a.map { |k, v| [k, v&.as_json] }.sort]]
end
|
#constructor_types ⇒ Object
789
790
791
792
793
794
795
796
797
798
|
# File 'lib/dhall/ast.rb', line 789
def constructor_types
alternatives.each_with_object({}) do |(k, type), ctypes|
ctypes[k] = if type.nil?
self
else
var = Util::BuiltinName === k ? "_" : k
Forall.new(var: var, type: type, body: self)
end
end
end
|
#eql?(other) ⇒ Boolean
764
765
766
|
# File 'lib/dhall/ast.rb', line 764
def eql?(other)
self == other
end
|
#fetch(k, default = nil) ⇒ Object
772
773
774
775
776
777
778
779
780
|
# File 'lib/dhall/ast.rb', line 772
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
782
783
784
785
786
787
|
# File 'lib/dhall/ast.rb', line 782
def get_constructor(selector)
var = Util::BuiltinName === selector ? "_" : selector
type = alternatives.fetch(selector)
body = Union.from(self, selector, Variable[var])
Function.new(var: var, type: type, body: body)
end
|
#merge(other) ⇒ Object
768
769
770
|
# File 'lib/dhall/ast.rb', line 768
def merge(other)
with(alternatives: alternatives.merge(other.alternatives))
end
|
#normalize ⇒ Object
328
329
330
|
# File 'lib/dhall/normalize.rb', line 328
def normalize
with(alternatives: Hash[super.alternatives.sort])
end
|
#record ⇒ Object
756
757
758
|
# File 'lib/dhall/ast.rb', line 756
def record
alternatives
end
|