tryMap<S, F extends Object> method

Result<Arr<S>, F> tryMap<S, F extends Object>(
  1. Result<S, F> f(
    1. T
    )
)

A fallible function f applied to each element on this array in order to return an array the same size as this or the first error encountered.

Implementation

Result<Arr<S>, F> tryMap<S, F extends Object>(Result<S, F> Function(T) f) {
  List<S?> result = List.filled(list.length, null, growable: false);
  for (int i = 0; i < list.length; i++) {
    var res = f(list[i]);
    if (res case Err()) {
      return res.into();
    }
    result[i] = res.unwrap();
  }
  return Ok(Arr._(result.cast<S>()));
}