flatMapSingleData<DATA_2 extends Object> method

Stream<LceState<DATA_2>> flatMapSingleData<DATA_2 extends Object>(
  1. Future<DATA_2> mapper(
    1. DATA data
    )
)

Maps each DATA to future for DATA_2 and merges back to LceState. If error occurs in mapper emits LceError. Example: load some DATA_2 from server using original DATA as a parameter. DATA_2 Resulting data type mapper Data mapper

Implementation

Stream<LceState<DATA_2>> flatMapSingleData<DATA_2 extends Object>(Future<DATA_2> Function(DATA data) mapper) =>
    asyncMap((state) async {
      final data1 = state.data;
      if (null == data1) {
        return LceState<DATA_2>.loading(null, false);
      } else {
        try {
          return state.combine(LceState.content(await mapper(data1), true), (_, data2) => data2);
        } on Exception catch (e) {
          return LceState.error(null, false, e);
        } catch (e) {
          return LceState.error(null, false, Exception(e.toString()));
        }
      }
    });