@@ -1020,6 +1020,36 @@ func (op *filterOperator) end(_ context.Context, _ chan<- Item) {
10201020func (op * filterOperator ) gatherNext (_ context.Context , _ Item , _ chan <- Item , _ operatorOptions ) {
10211021}
10221022
1023+ // Find emits the first item passing a predicate then complete.
1024+ func (o * ObservableImpl ) Find (find Predicate , opts ... Option ) OptionalSingle {
1025+ return optionalSingle (o , func () operator {
1026+ return & findOperator {
1027+ find : find ,
1028+ }
1029+ }, true , true , opts ... )
1030+ }
1031+
1032+ type findOperator struct {
1033+ find Predicate
1034+ }
1035+
1036+ func (op * findOperator ) next (ctx context.Context , item Item , dst chan <- Item , operatorOptions operatorOptions ) {
1037+ if op .find (item .V ) {
1038+ item .SendContext (ctx , dst )
1039+ operatorOptions .stop ()
1040+ }
1041+ }
1042+
1043+ func (op * findOperator ) err (ctx context.Context , item Item , dst chan <- Item , operatorOptions operatorOptions ) {
1044+ defaultErrorFuncOperator (ctx , item , dst , operatorOptions )
1045+ }
1046+
1047+ func (op * findOperator ) end (_ context.Context , _ chan <- Item ) {
1048+ }
1049+
1050+ func (op * findOperator ) gatherNext (_ context.Context , _ Item , _ chan <- Item , _ operatorOptions ) {
1051+ }
1052+
10231053// First returns new Observable which emit only first item.
10241054// Cannot be run in parallel.
10251055func (o * ObservableImpl ) First (opts ... Option ) OptionalSingle {
0 commit comments