class Dhall::Union
Public Class Methods
decode(tag, value, alternatives)
click to toggle source
# File lib/dhall/binary.rb, line 184 def self.decode(tag, value, alternatives) new( tag: tag, value: Dhall.decode(value), alternatives: UnionType.decode(alternatives) ) end
from(alts, tag, value)
click to toggle source
# File lib/dhall/ast.rb, line 1024 def self.from(alts, tag, value) if value.nil? Enum.new(tag: tag, alternatives: alts.without(tag)) else new( tag: tag, value: TypeAnnotation.new(value: value, type: alts[tag]), alternatives: alts.without(tag) ) end end
Public Instance Methods
as_json()
click to toggle source
# File lib/dhall/ast.rb, line 1071 def as_json if value.respond_to?(:type) syntax.as_json else [12, tag, value&.as_json, alternatives.as_json.last] end end
extract()
click to toggle source
# File lib/dhall/ast.rb, line 1040 def extract if value.is_a?(TypeAnnotation) value.value else value end end
normalize()
click to toggle source
# File lib/dhall/normalize.rb, line 378 def normalize val = if value.is_a?(TypeAnnotation) value.with(ExpressionVisitor.new(&:normalize).visit(value)) else value&.normalize end with(value: val, alternatives: alternatives.normalize) end
reduce(handlers)
click to toggle source
# File lib/dhall/ast.rb, line 1048 def reduce(handlers) handlers = handlers.to_h handler = handlers.fetch(tag.to_sym) { handlers.fetch(tag) } (handler.respond_to?(:to_proc) ? handler.to_proc : handler) .call(extract) end
selection_syntax()
click to toggle source
# File lib/dhall/ast.rb, line 1055 def selection_syntax RecordSelection.new( record: alternatives.merge( UnionType.new(alternatives: { tag => value&.type }) ), selector: tag ) end
syntax()
click to toggle source
# File lib/dhall/ast.rb, line 1064 def syntax Application.new( function: selection_syntax, argument: value.is_a?(TypeAnnotation) ? value.value : value ) end
to_s()
click to toggle source
# File lib/dhall/ast.rb, line 1036 def to_s extract.to_s end