Refactor sampleN code and remove log
This commit is contained in:
parent
ffaf349e0a
commit
5bdc19f35f
|
@ -19,15 +19,6 @@ open Reducer_ErrorValue
|
||||||
|
|
||||||
exception TestRescriptException
|
exception TestRescriptException
|
||||||
|
|
||||||
let parseSampleSetArray = (arr: array<internalExpressionValue>): option<array<SampleSetDist.t>> => {
|
|
||||||
let parseSampleSet = (value: internalExpressionValue): option<SampleSetDist.t> =>
|
|
||||||
switch value {
|
|
||||||
| IEvDistribution(SampleSet(dist)) => Some(dist)
|
|
||||||
| _ => None
|
|
||||||
}
|
|
||||||
E.A.O.openIfAllSome(E.A.fmap(parseSampleSet, arr))
|
|
||||||
}
|
|
||||||
|
|
||||||
let callInternal = (call: functionCall, environment, reducer: ExpressionT.reducerFn): result<
|
let callInternal = (call: functionCall, environment, reducer: ExpressionT.reducerFn): result<
|
||||||
'b,
|
'b,
|
||||||
errorValue,
|
errorValue,
|
||||||
|
@ -159,9 +150,25 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
|
||||||
SampleSetDist.map3(~fn, ~t1, ~t2, ~t3)->toType
|
SampleSetDist.map3(~fn, ~t1, ~t2, ~t3)->toType
|
||||||
}
|
}
|
||||||
|
|
||||||
let mapN = (t1: array<t>, aLambdaValue) => {
|
let mapN = (aValueArray: array<internalExpressionValue>, aLambdaValue) => {
|
||||||
|
switch parseSampleSetArray(aValueArray) {
|
||||||
|
| Some(t1) =>
|
||||||
let fn = a => doLambdaCall(aLambdaValue, list{IEvArray(E.A.fmap(x => IEvNumber(x), a))})
|
let fn = a => doLambdaCall(aLambdaValue, list{IEvArray(E.A.fmap(x => IEvNumber(x), a))})
|
||||||
SampleSetDist.mapN(~fn, ~t1)->toType
|
SampleSetDist.mapN(~fn, ~t1)->toType
|
||||||
|
| None =>
|
||||||
|
Error(REFunctionNotFound(call->functionCallToCallSignature->functionCallSignatureToString))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let parseSampleSetArray = (arr: array<internalExpressionValue>): option<
|
||||||
|
array<SampleSetDist.t>,
|
||||||
|
> => {
|
||||||
|
let parseSampleSet = (value: internalExpressionValue): option<SampleSetDist.t> =>
|
||||||
|
switch value {
|
||||||
|
| IEvDistribution(SampleSet(dist)) => Some(dist)
|
||||||
|
| _ => None
|
||||||
|
}
|
||||||
|
E.A.O.openIfAllSome(E.A.fmap(parseSampleSet, arr))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,11 +252,7 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
|
||||||
) =>
|
) =>
|
||||||
SampleMap.map3(dist1, dist2, dist3, aLambdaValue)
|
SampleMap.map3(dist1, dist2, dist3, aLambdaValue)
|
||||||
| ("mapSamplesN", [IEvArray(aValueArray), IEvLambda(aLambdaValue)]) =>
|
| ("mapSamplesN", [IEvArray(aValueArray), IEvLambda(aLambdaValue)]) =>
|
||||||
switch parseSampleSetArray(aValueArray) {
|
SampleMap.mapN(aValueArray, aLambdaValue)
|
||||||
| Some(sampleSetArr) => SampleMap.mapN(sampleSetArr, aLambdaValue)
|
|
||||||
| None =>
|
|
||||||
Error(REFunctionNotFound(call->functionCallToCallSignature->functionCallSignatureToString))
|
|
||||||
}
|
|
||||||
| ("reduce", [IEvArray(aValueArray), initialValue, IEvLambda(aLambdaValue)]) =>
|
| ("reduce", [IEvArray(aValueArray), initialValue, IEvLambda(aLambdaValue)]) =>
|
||||||
doReduceArray(aValueArray, initialValue, aLambdaValue)
|
doReduceArray(aValueArray, initialValue, aLambdaValue)
|
||||||
| ("reduceReverse", [IEvArray(aValueArray), initialValue, IEvLambda(aLambdaValue)]) =>
|
| ("reduceReverse", [IEvArray(aValueArray), initialValue, IEvLambda(aLambdaValue)]) =>
|
||||||
|
@ -281,8 +284,5 @@ let dispatch = (call: functionCall, environment, reducer: ExpressionT.reducerFn)
|
||||||
ExternalLibrary.dispatch((Js.String.make(fn), args), environment, callInternalWithReducer)
|
ExternalLibrary.dispatch((Js.String.make(fn), args), environment, callInternalWithReducer)
|
||||||
} catch {
|
} catch {
|
||||||
| Js.Exn.Error(obj) => REJavaScriptExn(Js.Exn.message(obj), Js.Exn.name(obj))->Error
|
| Js.Exn.Error(obj) => REJavaScriptExn(Js.Exn.message(obj), Js.Exn.name(obj))->Error
|
||||||
| err => {
|
| _ => RETodo("unhandled rescript exception")->Error
|
||||||
Js.Console.log(err)
|
|
||||||
RETodo("unhandled rescript exception")->Error
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user