import { IterableX } from '../iterablex' ; import { identity } from '../../util/identity' ; import { comparer as defaultComparer } from '../../util/comparer' ; import { MonoTypeOperatorFunction } from '../../interfaces' ; import { DistinctOptions } from './distinctoptions' ; export class DistinctUntilChangedIterable < TSource , TKey = TSource > extends IterableX < TSource > { private _source : Iterable < TSource > ; private _keySelector : ( value : TSource ) => TKey ; private _comparer : ( x : TKey , y : TKey ) => boolean ; constructor ( source , keySelector , comparer ) { super ( ) ; this . _source = source ; this . _keySelector = keySelector ; this . _comparer = comparer ; } * [ Symbol . iterator ] ( ) { let currentKey = < TKey > { } ; let hasCurrentKey = false ; for ( const item of this . _source ) { const key = this . _keySelector ( item ) ; let comparerEquals = false ; if ( hasCurrentKey ) { comparerEquals = this . _comparer ( currentKey , key ) ; } if ( ! hasCurrentKey || ! comparerEquals ) { hasCurrentKey = true ; currentKey = key ; yield item ; } } } } template TSource template TKey param { DistinctOptions < TSource , TKey = TSource returns { MonoTypeOperatorFunction < TSource > } export function distinctUntilChanged < TSource , TKey = TSource > ( options ? ) { return function distinctUntilChangedOperatorFunction ( source ) : IterableX < TSource > { const { [ 'keySelector' ] : keySelector = identity , [ 'comparer' ] : comparer = defaultComparer } = options || { } ; return new DistinctUntilChangedIterable < TSource , TKey > ( source , keySelector ! , comparer ! ) ; } ; }