import { Source } from "../activities/activity" ; import { each } from "../activities/each" ; export type AccessorT < T , U > = ( row : T , currentIndex : number ) => U ; export interface ObserverFactory < T , U > { ( ) : Observer < T , U > ; } export interface Observer < T , U > { observe ( r , idx ) : void ; peek ( ) : U ; } export function Accessor < T = any , U = any , V = any > ( fof , accesor ) { const s = fof ( ) ; return { observe : ( _ , i ) => { s . observe ( accesor ( _ , i ) , i ) ; } , peek : s . peek } ; } export function sensor < T , U = any > ( s ) { return each ( ( r , i ) => s . observe ( r , i ) ) ; } export function activity < T , U > ( s ) { return function * ( source ) { let i = - 1 ; for ( const row of source ) { s . observe ( row , ++ i ) ; } yield s . peek ( ) ; } ; } export function scalar < T = any , U = any > ( s ) { return function ( source ) { let i = - 1 ; for ( const row of source ) { s . observe ( row , ++ i ) ; } return s . peek ( ) ; } ; }