Class: Dhall::AsDhall::ExpressionList::Union
- Inherits:
-
Object
- Object
- Dhall::AsDhall::ExpressionList::Union
- Defined in:
- lib/dhall/as_dhall.rb
Instance Method Summary collapse
-
#initialize(values, exprs, types) ⇒ Union
constructor
A new instance of Union.
- #list ⇒ Object
Constructor Details
#initialize(values, exprs, types) ⇒ Union
Returns a new instance of Union.
197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/dhall/as_dhall.rb', line 197 def initialize(values, exprs, types) @tags, @types = values.zip(types).map { |(value, type)| if type.is_a?(UnionType) && type.alternatives.length == 1 type.alternatives.to_a.first else [AsDhall.tag_for(value), type] end }.transpose @exprs = exprs @inferer = UnionInferer.new end |
Instance Method Details
#list ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/dhall/as_dhall.rb', line 209 def list final_inferer = @tags .zip(@exprs, @types) .reduce(@inferer) do |inferer, (tag, expr, type)| inferer.with( tag, type.nil? ? nil : TypeAnnotation.new(value: expr, type: type) ) end List.new(elements: @exprs.map(&final_inferer.method(:union_for))) end |