import { IterableX } from '../iterablex' ; import { create } from '../create' ; import { OperatorFunction } from '../../interfaces' ; class SharedIterable < T > extends IterableX < T > { private _it : Iterator < T > ; constructor ( it ) { super ( ) ; this . _it = { next ( value ) { return it . next ( value ) ; } , } ; } [ Symbol . iterator ] ( ) { return this . _it ; } } template TSource returns { OperatorAsyncFunction < TSource , TSource > } export function share < TSource > ( ) ; template TSource template TResult param { ( ( value : Iterable < TSource > ) => Iterable < TResult > ) } selector returns { OperatorAsyncFunction < TSource , TResult > } export function share < TSource , TResult > ( selector ? ) ; template TSource template TResult param { ( ( value : Iterable < TSource > ) => Iterable < TResult > ) } selector returns { ( OperatorFunction < TSource , TSource | TResult > ) } export function share < TSource , TResult = TSource > ( selector ? ) { return function shareOperatorFunction ( source ) : IterableX < TSource | TResult > { return selector ? create ( ( ) => selector ( new SharedIterable ( source [ Symbol . iterator ] ( ) ) ) [ Symbol . iterator ] ( ) ) : new SharedIterable ( source [ Symbol . iterator ] ( ) ) ; } ; }