From 5ce0a6979d9f95d77e4ddbdffc40009de73821e3 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Tue, 6 Sep 2022 13:39:02 +0200 Subject: [PATCH] tweak: Also use helpers in Number lib Avoids code duplication --- .../FunctionRegistry/Library/FR_Number.res | 32 +++++-------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Number.res b/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Number.res index 472ae60b..6305855d 100644 --- a/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Number.res +++ b/packages/squiggle-lang/src/rescript/FunctionRegistry/Library/FR_Number.res @@ -4,22 +4,6 @@ open FunctionRegistry_Helpers let nameSpace = "Number" let requiresNamespace = false -module NumberToNumber = { - let make = (name, fn) => - FnDefinition.make( - ~name, - ~inputs=[FRTypeNumber], - ~run=(_, inputs, _, _) => { - inputs - ->getOrError(0) - ->E.R.bind(Prepare.oneNumber) - ->E.R2.fmap(fn) - ->E.R2.fmap(Wrappers.evNumber) - }, - (), - ) -} - module ArrayNumberDist = { let make = (name, fn) => { FnDefinition.make( @@ -52,7 +36,7 @@ let library = [ ~requiresNamespace, ~output=EvtNumber, ~examples=[`floor(3.5)`], - ~definitions=[NumberToNumber.make("floor", Js.Math.floor_float)], + ~definitions=[DefineFn.Numbers.oneToOne("floor", Js.Math.floor_float)], (), ), Function.make( @@ -61,7 +45,7 @@ let library = [ ~requiresNamespace, ~output=EvtNumber, ~examples=[`ceil(3.5)`], - ~definitions=[NumberToNumber.make("ceil", Js.Math.ceil_float)], + ~definitions=[DefineFn.Numbers.oneToOne("ceil", Js.Math.ceil_float)], (), ), Function.make( @@ -70,7 +54,7 @@ let library = [ ~requiresNamespace, ~output=EvtNumber, ~examples=[`abs(3.5)`], - ~definitions=[NumberToNumber.make("abs", Js.Math.abs_float)], + ~definitions=[DefineFn.Numbers.oneToOne("abs", Js.Math.abs_float)], (), ), Function.make( @@ -79,7 +63,7 @@ let library = [ ~requiresNamespace, ~output=EvtNumber, ~examples=[`exp(3.5)`], - ~definitions=[NumberToNumber.make("exp", Js.Math.exp)], + ~definitions=[DefineFn.Numbers.oneToOne("exp", Js.Math.exp)], (), ), Function.make( @@ -88,7 +72,7 @@ let library = [ ~requiresNamespace, ~output=EvtNumber, ~examples=[`log(3.5)`], - ~definitions=[NumberToNumber.make("log", Js.Math.log)], + ~definitions=[DefineFn.Numbers.oneToOne("log", Js.Math.log)], (), ), Function.make( @@ -97,7 +81,7 @@ let library = [ ~requiresNamespace, ~output=EvtNumber, ~examples=[`log10(3.5)`], - ~definitions=[NumberToNumber.make("log10", Js.Math.log10)], + ~definitions=[DefineFn.Numbers.oneToOne("log10", Js.Math.log10)], (), ), Function.make( @@ -106,7 +90,7 @@ let library = [ ~requiresNamespace, ~output=EvtNumber, ~examples=[`log2(3.5)`], - ~definitions=[NumberToNumber.make("log2", Js.Math.log2)], + ~definitions=[DefineFn.Numbers.oneToOne("log2", Js.Math.log2)], (), ), Function.make( @@ -115,7 +99,7 @@ let library = [ ~requiresNamespace, ~output=EvtNumber, ~examples=[`round(3.5)`], - ~definitions=[NumberToNumber.make("round", Js.Math.round)], + ~definitions=[DefineFn.Numbers.oneToOne("round", Js.Math.round)], (), ), Function.make(