feat: In Danger namespace, work out how to apply function
This commit is contained in:
parent
b57233096d
commit
b45ab3dba2
|
@ -61,25 +61,18 @@ module Internals = {
|
||||||
let choose = ((n, k)) => factorial(n) /. (factorial(n -. k) *. factorial(k))
|
let choose = ((n, k)) => factorial(n) /. (factorial(n -. k) *. factorial(k))
|
||||||
let pow = (base, exp) => Js.Math.pow_float(~base, ~exp)
|
let pow = (base, exp) => Js.Math.pow_float(~base, ~exp)
|
||||||
let binomial = ((n, k, p)) => choose((n, k)) *. pow(p, k) *. pow(1.0 -. p, n -. k)
|
let binomial = ((n, k, p)) => choose((n, k)) *. pow(p, k) *. pow(1.0 -. p, n -. k)
|
||||||
let map = (array: array<internalExpressionValue>, environment, eLambdaValue, reducer): result<
|
let applyFunctionAtPoint = (aLambda, internalNumber: internalExpressionValue, environment , reducer): result<
|
||||||
ReducerInterface_InternalExpressionValue.t,
|
ReducerInterface_InternalExpressionValue.t,
|
||||||
Reducer_ErrorValue.errorValue,
|
Reducer_ErrorValue.errorValue,
|
||||||
> => {
|
> => {
|
||||||
let x = array[0]
|
let x = internalNumber
|
||||||
let wrappedY = {
|
let result = Reducer_Expression_Lambda.doLambdaCall(
|
||||||
let result2 = Reducer_Expression_Lambda.doLambdaCall(
|
aLambda,
|
||||||
eLambdaValue,
|
list{x},
|
||||||
list{x},
|
environment,
|
||||||
environment,
|
reducer,
|
||||||
reducer,
|
)
|
||||||
)
|
result
|
||||||
let result3 = switch(result2){
|
|
||||||
| Ok(a) => Ok(list{a})
|
|
||||||
| Error(b) => Error(b)
|
|
||||||
}
|
|
||||||
result3
|
|
||||||
}
|
|
||||||
wrappedY->E.R2.fmap(mappedList => mappedList->Belt.List.toArray->Wrappers.evArray)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -135,19 +128,19 @@ let library = [
|
||||||
(),
|
(),
|
||||||
),
|
),
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="map",
|
~name="applyFunctionAtPoint",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
~output=EvtArray,
|
~output=EvtArray,
|
||||||
~requiresNamespace=false,
|
~requiresNamespace=false,
|
||||||
~examples=[`List.map([1,4,5], {|x| x+1})`],
|
~examples=[`Danger.applyFunctionAtPoint({|x| x+1}, 1)`],
|
||||||
~definitions=[
|
~definitions=[
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name="map",
|
~name="applyFunctionAtPoint",
|
||||||
~inputs=[FRTypeArray(FRTypeAny), FRTypeLambda],
|
~inputs=[FRTypeLambda, FRTypeNumber],
|
||||||
~run=(inputs, _, env, reducer) =>
|
~run=(inputs, _, env, reducer) =>
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvArray(array), IEvLambda(lambda)] =>
|
| [IEvLambda(aLambda), point] =>
|
||||||
Internals.map(array, env, lambda, reducer)->E.R2.errMap(_ => "Error!")
|
Internals.applyFunctionAtPoint(aLambda, point, env, reducer)->E.R2.errMap(_ => "Error!")
|
||||||
| _ => Error(impossibleError)
|
| _ => Error(impossibleError)
|
||||||
},
|
},
|
||||||
(),
|
(),
|
||||||
|
|
Loading…
Reference in New Issue
Block a user