MCPcopy Create free account
hub / github.com/ReactiveX/RxGo / FlatMap

Method FlatMap

observable_operator.go:1112–1151  ·  view source on GitHub ↗

FlatMap transforms the items emitted by an Observable into Observables, then flatten the emissions from those into a single Observable.

(apply ItemToObservable, opts ...Option)

Source from the content-addressed store, hash-verified

1110
1111// FlatMap transforms the items emitted by an Observable into Observables, then flatten the emissions from those into a single Observable.
1112func (o *ObservableImpl) FlatMap(apply ItemToObservable, opts ...Option) Observable {
1113 f := func(ctx context.Context, next chan Item, option Option, opts ...Option) {
1114 defer close(next)
1115 observe := o.Observe(opts...)
1116 for {
1117 select {
1118 case <-ctx.Done():
1119 return
1120 case item, ok := <-observe:
1121 if !ok {
1122 return
1123 }
1124 observe2 := apply(item).Observe(opts...)
1125 loop2:
1126 for {
1127 select {
1128 case <-ctx.Done():
1129 return
1130 case item, ok := <-observe2:
1131 if !ok {
1132 break loop2
1133 }
1134 if item.Error() {
1135 item.SendContext(ctx, next)
1136 if option.getErrorStrategy() == StopOnError {
1137 return
1138 }
1139 } else {
1140 if !item.SendContext(ctx, next) {
1141 return
1142 }
1143 }
1144 }
1145 }
1146 }
1147 }
1148 }
1149
1150 return customObservableOperator(o.parent, f, opts...)
1151}
1152
1153// ForEach subscribes to the Observable and receives notifications for each element.
1154func (o *ObservableImpl) ForEach(nextFunc NextFunc, errFunc ErrFunc, completedFunc CompletedFunc, opts ...Option) Disposed {

Callers

nothing calls this directly

Calls 6

ObserveMethod · 0.95
customObservableOperatorFunction · 0.85
SendContextMethod · 0.80
ObserveMethod · 0.65
ErrorMethod · 0.65
getErrorStrategyMethod · 0.65

Tested by

no test coverage detected