class Steep::AST::Types::Union
def self.build(types:, location: nil)
def self.build(types:, location: nil) types.flat_map do |type| if type.is_a?(Union) type.types else [type] end end.map do |type| case type when AST::Types::Any return AST::Types::Any.new(location: location) when AST::Types::Top return AST::Types::Top.new(location: location) when AST::Types::Bot nil else type end end.compact.uniq.yield_self do |tys| if tys.length == 1 tys.first else new(types: tys.sort_by(&:hash), location: location) end end end