File tree Expand file tree Collapse file tree 2 files changed +10
-51
lines changed
test/Rx/Functional/Operator Expand file tree Collapse file tree 2 files changed +10
-51
lines changed Original file line number Diff line number Diff line change @@ -18,8 +18,13 @@ class DistinctOperator implements OperatorInterface
1818
1919 public function __construct (callable $ keySelector = null , callable $ comparer = null )
2020 {
21- $ this ->comparer = $ comparer ;
21+
22+ $ this ->comparer = $ comparer ?: function ($ x , $ y ) {
23+ return $ x == $ y ;
24+ };
25+
2226 $ this ->keySelector = $ keySelector ;
27+
2328 }
2429
2530 /**
@@ -38,22 +43,15 @@ function ($value) use ($observer, &$values) {
3843 try {
3944 $ key = $ this ->keySelector ? call_user_func ($ this ->keySelector , $ value ) : $ value ;
4045
41- if ($ this ->comparer ) {
42- foreach ($ values as $ v ) {
43- $ comparerEquals = call_user_func ($ this ->comparer , $ key , $ v );
46+ foreach ($ values as $ v ) {
47+ $ comparerEquals = call_user_func ($ this ->comparer , $ key , $ v );
4448
45- if ($ comparerEquals ) {
46- return ;
47- }
48- }
49- $ values [] = $ key ;
50- } else {
51- if (array_key_exists ($ key , $ values )) {
49+ if ($ comparerEquals ) {
5250 return ;
5351 }
54- $ values [$ key ] = null ;
5552 }
5653
54+ $ values [] = $ key ;
5755 $ observer ->onNext ($ value );
5856
5957 } catch (\Exception $ e ) {
Original file line number Diff line number Diff line change @@ -353,45 +353,6 @@ public function distinct_CustomKey_some_throw()
353353
354354 }
355355
356- /**
357- * @test
358- */
359- public function distinct_CustomKey_and_CustomComparer_some_duplicates ()
360- {
361-
362- $ xs = $ this ->createHotObservable ([
363- onNext (280 , ['id ' => 4 ]),
364- onNext (300 , ['id ' => 2 ]),
365- onNext (350 , ['id ' => 12 ]),
366- onNext (380 , ['id ' => 3 ]),
367- onNext (400 , ['id ' => 24 ]),
368- onCompleted (420 )
369- ]);
370-
371- $ results = $ this ->scheduler ->startWithCreate (function () use ($ xs ) {
372- return $ xs ->distinctKey (
373- function ($ x ) {
374- return $ x ['id ' ];
375- },
376- $ this ->modComparer (10 )
377- )->map (function ($ x ) {
378- return $ x ['id ' ];
379- });
380- });
381-
382- $ this ->assertMessages ([
383- onNext (280 , 4 ),
384- onNext (300 , 2 ),
385- onNext (380 , 3 ),
386- onCompleted (420 )
387- ], $ results ->getMessages ());
388-
389- $ this ->assertSubscriptions ([
390- subscribe (200 , 420 )
391- ], $ xs ->getSubscriptions ());
392-
393- }
394-
395356
396357 public function modComparer ($ mod )
397358 {
You can’t perform that action at this time.
0 commit comments