/**
 * Copyright (c) 2016-present, Facebook, Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */ import * as LazySequence from './lazy-sequence' ; import * as Logging from './logging' ; import * as Promise from './promise' ; function performanceLog < T > ( name , startTime , stopTime , value ) { return Logging . Performance ( 10 , name + ': ' + ( stopTime . getTime ( ) - startTime . getTime ( ) ) , value ) ; } function toAsyncLoggingPipelineForm < T , U > ( f ) { return function ( future ) { return Promise . mbind ( function ( context ) { const value = Logging . getValue ( context ) ; const beforeTime = new Date ( ) ; const result = f ( value ) ; return Promise . map ( function ( resultContext ) { const afterTime = new Date ( ) ; const func = f ; const combinedContext = Logging . mbind ( function ( t ) { return resultContext ; } , context ) ; return Logging . mbind ( function ( u ) { return performanceLog ( func . name , beforeTime , afterTime , u ) ; } , combinedContext ) ; } , result ) ; } , future ) ; } ; } export function mapLoggedSequence < T , U > ( seq , f ) { return seq . map ( toAsyncLoggingPipelineForm ( f ) ) ; } export function mapLoggedSequence3 < T , U , V > ( seq , f , g ) { return seq . map ( toAsyncLoggingPipelineForm ( f ) ) . map ( toAsyncLoggingPipelineForm ( g ) ) ; } function evaluateFutureLoggingForLogger < T > ( logger ) { return function ( future ) { return Promise . map ( function ( context ) { return Logging . evaluate ( logger , context ) ; } , future ) ; } ; } export function evaluatedLoggedSequence < T > ( logger , seq ) { const evaluateLoggingContext = evaluateFutureLoggingForLogger < T > ( logger ) ; return seq . map ( evaluateLoggingContext ) ; }