Class: Dhall::AsDhall::ExpressionList::Union

Inherits:
Object
  • Object
show all
Defined in:
lib/dhall/as_dhall.rb

Instance Method Summary collapse

Constructor Details

#initialize(values, exprs, types) ⇒ 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

#listObject



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