import { id } from "../../tools/typeSafety/id"; import { Operator } from "../types/Operator"; export function encapsulateOpState( statefulFλOp: Operator.fλ.Stateful ): Operator.fλ.Stateless { let state: U = statefulFλOp[1]; return id>( (...[data, , cbInvokedIfMatched]) => { const opResult = statefulFλOp[0](data, state, cbInvokedIfMatched); if ( !!cbInvokedIfMatched && Operator.fλ.Result.Matched.match(opResult) ) { state = opResult[0]; } return opResult; } ); }