upcast<T> method

T? upcast<T>(
  1. T supplier(
    1. Object? source
    )
)

Extension methods that simplify adapting Object? values into strongly typed collections or custom types using Jetleaf's TypeAdapter system.

These helpers provide a convenient way to "upcast" raw dynamic data into proper Dart types.

Example

Object? rawList = [1, 2, 3];
final list = rawList.upcastToList<int>(); // [1, 2, 3]

Object? rawMap = {'a': 1, 'b': 2};
final map = rawMap.upcastToMap<String, int>(); // {a: 1, b: 2}

Object? rawSet = {10, 20, 30};
final set = rawSet.upcastToSet<int>(); // {10, 20, 30}

Object? value = 'hello';
final upper = value.upcast<String>((src) => src.toString().toUpperCase());
// "HELLO"

Implementation

T? upcast<T>(T Function(Object? source) supplier) {
  if (this == null) return null;
  return supplier(this);
}