import zipper from "./zipper" ; import { identity } from "./identity" ; interface Merge { ( data ) : any ; algorithm ( ) : any ; algorithm ( newAlgorithm ) : Merge ; merge ( ) : any ; merge ( newMerge ) : Merge ; skipUndefined ( ) : boolean ; skipUndefined ( newSkipUndefined ) : Merge ; } export default function ( ) { let algorithm = identity ; let skipUndefined = true ; let merge = ( ) => { } ; const mergeCompute = ( data ) => { const zip = zipper ( ) . combine ( ( datum , indicator ) => { const result = skipUndefined && indicator === undefined ? datum : merge ( datum , indicator ) ; return result === undefined ? datum : result ; } ) ; return zip ( data , algorithm ( data ) ) ; } ; mergeCompute . algorithm = ( newAlgorithm ? ) => { if ( newAlgorithm === undefined ) { return algorithm ; } algorithm = newAlgorithm ; return mergeCompute ; } ; mergeCompute . merge = ( newMerge ? ) => { if ( newMerge === undefined ) { return merge ; } merge = newMerge ; return mergeCompute ; } ; mergeCompute . skipUndefined = ( newSkipUndefined ? ) => { if ( newSkipUndefined === undefined ) { return skipUndefined ; } skipUndefined = newSkipUndefined ; return mergeCompute ; } ; return mergeCompute as Merge ; }