module T::Utils

def self.unwrap_nilable(type)

If so, returns the T::Types::Base of the something else. Otherwise, returns nil.
Give a type which is a subclass of T::Types::Base, determines if the type is a simple nilable type (union of NilClass and something else).
def self.unwrap_nilable(type)
  case type
  when T::Types::Union
    non_nil_types = type.types.reject {|t| t == Nilable::NIL_TYPE}
    return nil if type.types.length == non_nil_types.length
    case non_nil_types.length
    when 0 then nil
    when 1 then non_nil_types.first
    else
      T::Types::Union::Private::Pool.union_of_types(non_nil_types[0], non_nil_types[1], non_nil_types[2..-1])
    end
  else
    nil
  end
end