A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://reactivex.io/documentation/operators/max.html below:

ReactiveX - Max operator

  1. Operators
  2. Mathematical and Aggregate
  3. Max
Max emits the item from the source Observable that had the maximum value

The Max operator operates on an Observable that emits numbers (or items that can be evaluated as numbers), and emits a single item: the item with the largest number.

See Also Language-Specific Information:

In RxGroovy, this operator is not in the ReactiveX core, but is part of the distinct rxjava-math module.

RxGroovy implements a max operator. It takes an optional comparator that it will use instead of its default to compare the value of two items. If more than one item has the identical maximum value, max will emit the last such item emitted by the source Observable.

The maxBy operator is similar to max, but instead of emitting the item with the maximum value, it emits the item with the maximum key, where that key is generated based on a function you provide to maxBy

In RxJava, this operator is not in the ReactiveX core, but is part of the distinct rxjava-math module.

RxJava implements a max operator. It takes an optional comparator that it will use instead of its default to compare the value of two items. If more than one item has the identical maximum value, max will emit the last such item emitted by the source Observable.

The maxBy operator is similar to max, but instead of emitting the item with the maximum value, it emits the item with the maximum key, where that key is generated based on a function you provide to maxBy

RxJS implements the max operator. It takes an optional comparer function that it will use instead of its default to compare the value of two items.

Sample Code
var source = Rx.Observable.fromArray([1,3,5,7,9,2,4,6,8]).max();

var subscription = source.subscribe(
  function (x) { console.log('Next: ' + x); },
  function (err) { console.log('Error: ' + err); },
  function () { console.log('Completed'); } );
Next: 9
Completed

The maxBy operator is similar to max, but instead of emitting the item with the maximum value, it emits the item with the maximum key, where that key is generated based on a function you provide to maxBy. maxBy also takes an optional second parameter: a comparer function that it will use instead of its default to compare the keys of the two items.

maxBy emits a list. If more than one item has the maximum key value, each such item will be represented in the list.

Sample Code
var source = Rx.Observable.fromArray([1,3,5,7,9,2,4,6,8,9])
               .maxBy( function (x) { return x; } );

var subscription = source.subscribe(
  function (x) { console.log('Next: ' + x); },
  function (err) { console.log('Error: ' + err); },
  function () { console.log('Completed'); } );
Next: 9,9
Completed

max and maxBy are found in the following distributions:

They requires one of the following:

RxPHP implements this operator as max.

Returns the maximum value in an observable sequence according to the specified comparer.

Sample Code
//from https://github.com/ReactiveX/RxPHP/blob/master/demo/max/max.php

/* Without comparer */
$source = \Rx\Observable::fromArray([1, 3, 5, 7, 9, 2, 4, 6, 8])
    ->max();

$subscription = $source->subscribe($createStdoutObserver());

   
Next value: 9
Complete!
    
//from https://github.com/ReactiveX/RxPHP/blob/master/demo/max/max-with-comparer.php

/* With a comparer */
$comparer = function ($x, $y) {
    if ($x > $y) {
        return 1;
    } elseif ($x < $y) {
        return -1;
    }
    return 0;
};

$source = \Rx\Observable::fromArray([1, 3, 5, 7, 9, 2, 4, 6, 8])
    ->max($comparer);

$subscription = $source->subscribe($createStdoutObserver());

   
Next value: 9
Complete!
    

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4