From f82c00a6edc06baa75779fdcb03cec0d769e4847 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Sun, 4 Sep 2022 19:29:22 +0200 Subject: [PATCH] tweak: Work out how to apply a function to an arbitrary value in the Danger domain --- .../FunctionRegistry/Library/FR_Danger.res | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Danger.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Danger.res index cc93abdb..974e8be0 100644 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Danger.res +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Danger.res @@ -74,6 +74,8 @@ module Internals = { ) result } + let internalZero = ReducerInterface_InternalExpressionValue.IEvNumber(0.0) + let applyFunctionAtZero = (aLambda) => applyFunctionAtPoint(aLambda, internalZero) } @@ -127,6 +129,27 @@ let library = [ ~definitions=[FunctionToNumberZero.make("functionToZero", x => x)], (), ), + Function.make( + ~name="applyFunctionAtZero", + ~nameSpace, + ~output=EvtArray, + ~requiresNamespace=false, + ~examples=[`Danger.applyFunctionAtZero({|x| x+1})`], + ~definitions=[ + FnDefinition.make( + ~name="applyFunctionAtPoint", + ~inputs=[FRTypeLambda], + ~run=(inputs, _, env, reducer) => + switch inputs { + | [IEvLambda(aLambda)] => + Internals.applyFunctionAtZero(aLambda, env, reducer)->E.R2.errMap(_ => "Error!") + | _ => Error(impossibleError) + }, + (), + ), + ], + (), + ), Function.make( ~name="applyFunctionAtPoint", ~nameSpace,