Format rescript
This commit is contained in:
parent
96a0d9c489
commit
b2ae31742e
|
@ -82,7 +82,10 @@ describe("FunctionRegistry Library", () => {
|
||||||
)
|
)
|
||||||
|
|
||||||
testEvalToBe("Dict.merge({a: 1, b: 2}, {b: 3, c: 4, d: 5})", "Ok({a: 1,b: 3,c: 4,d: 5})")
|
testEvalToBe("Dict.merge({a: 1, b: 2}, {b: 3, c: 4, d: 5})", "Ok({a: 1,b: 3,c: 4,d: 5})")
|
||||||
testEvalToBe("Dict.mergeMany([{a: 1, b: 2}, {c: 3, d: 4}, {c: 5, e: 6}])", "Ok({a: 1,b: 2,c: 5,d: 4,e: 6})")
|
testEvalToBe(
|
||||||
|
"Dict.mergeMany([{a: 1, b: 2}, {c: 3, d: 4}, {c: 5, e: 6}])",
|
||||||
|
"Ok({a: 1,b: 2,c: 5,d: 4,e: 6})",
|
||||||
|
)
|
||||||
testEvalToBe("Dict.keys({a: 1, b: 2})", "Ok(['a','b'])")
|
testEvalToBe("Dict.keys({a: 1, b: 2})", "Ok(['a','b'])")
|
||||||
testEvalToBe("Dict.values({a: 1, b: 2})", "Ok([1,2])")
|
testEvalToBe("Dict.values({a: 1, b: 2})", "Ok([1,2])")
|
||||||
testEvalToBe("Dict.toList({a: 1, b: 2})", "Ok([['a',1],['b',2]])")
|
testEvalToBe("Dict.toList({a: 1, b: 2})", "Ok([['a',1],['b',2]])")
|
||||||
|
|
|
@ -59,7 +59,6 @@ let library = [
|
||||||
],
|
],
|
||||||
(),
|
(),
|
||||||
),
|
),
|
||||||
|
|
||||||
Function.make(
|
Function.make(
|
||||||
~name="mergeMany",
|
~name="mergeMany",
|
||||||
~nameSpace,
|
~nameSpace,
|
||||||
|
@ -72,12 +71,15 @@ let library = [
|
||||||
~inputs=[FRTypeArray(FRTypeDict(FRTypeAny))],
|
~inputs=[FRTypeArray(FRTypeDict(FRTypeAny))],
|
||||||
~run=(inputs, _, _) => {
|
~run=(inputs, _, _) => {
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvArray(dicts)] => {
|
| [IEvArray(dicts)] => dicts
|
||||||
dicts->Belt.Array.map(dictValue => switch dictValue {
|
->Belt.Array.map(dictValue =>
|
||||||
|
switch dictValue {
|
||||||
| IEvRecord(dict) => dict
|
| IEvRecord(dict) => dict
|
||||||
| _ => impossibleError->Reducer_ErrorValue.toException
|
| _ => impossibleError->Reducer_ErrorValue.toException
|
||||||
})->Internals.mergeMany->Ok
|
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
->Internals.mergeMany
|
||||||
|
->Ok
|
||||||
| _ => impossibleError->Error
|
| _ => impossibleError->Error
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -22,8 +22,7 @@ module DistributionCreation = {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeDistOrNumber, FRTypeDistOrNumber],
|
~inputs=[FRTypeDistOrNumber, FRTypeDistOrNumber],
|
||||||
~run=(inputs, env, _) =>
|
~run=(inputs, env, _) => inputs->Prepare.ToValueTuple.twoDistOrNumber->process(~fn, ~env),
|
||||||
inputs->Prepare.ToValueTuple.twoDistOrNumber->process(~fn, ~env),
|
|
||||||
(),
|
(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -43,7 +42,9 @@ module DistributionCreation = {
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeRecord([("mean", FRTypeDistOrNumber), ("stdev", FRTypeDistOrNumber)])],
|
~inputs=[FRTypeRecord([("mean", FRTypeDistOrNumber), ("stdev", FRTypeDistOrNumber)])],
|
||||||
~run=(inputs, env, _) =>
|
~run=(inputs, env, _) =>
|
||||||
inputs->Prepare.ToValueTuple.Record.twoDistOrNumber(("mean", "stdev"))->process(~fn, ~env),
|
inputs
|
||||||
|
->Prepare.ToValueTuple.Record.twoDistOrNumber(("mean", "stdev"))
|
||||||
|
->process(~fn, ~env),
|
||||||
(),
|
(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -60,8 +61,7 @@ module DistributionCreation = {
|
||||||
FnDefinition.make(
|
FnDefinition.make(
|
||||||
~name,
|
~name,
|
||||||
~inputs=[FRTypeDistOrNumber],
|
~inputs=[FRTypeDistOrNumber],
|
||||||
~run=(inputs, env, _) =>
|
~run=(inputs, env, _) => inputs->Prepare.ToValueTuple.oneDistOrNumber->process(~fn, ~env),
|
||||||
inputs->Prepare.ToValueTuple.oneDistOrNumber->process(~fn, ~env),
|
|
||||||
(),
|
(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,8 @@ let requiresNamespace = true
|
||||||
let inputsToDist = (inputs: array<Reducer_T.value>, xyShapeToPointSetDist) => {
|
let inputsToDist = (inputs: array<Reducer_T.value>, xyShapeToPointSetDist) => {
|
||||||
// TODO - rewrite in more functional/functor-based style
|
// TODO - rewrite in more functional/functor-based style
|
||||||
switch inputs {
|
switch inputs {
|
||||||
| [IEvArray(items)] => {
|
| [IEvArray(items)] => items
|
||||||
items->Belt.Array.map(
|
->Belt.Array.map(item =>
|
||||||
item =>
|
|
||||||
switch item {
|
switch item {
|
||||||
| IEvRecord(map) => {
|
| IEvRecord(map) => {
|
||||||
let xValue = map->Belt.Map.String.get("x")
|
let xValue = map->Belt.Map.String.get("x")
|
||||||
|
@ -21,9 +20,10 @@ let inputsToDist = (inputs: array<Reducer_T.value>, xyShapeToPointSetDist) => {
|
||||||
}
|
}
|
||||||
| _ => impossibleError->Reducer_ErrorValue.toException
|
| _ => impossibleError->Reducer_ErrorValue.toException
|
||||||
}
|
}
|
||||||
)->Ok->E.R.bind(r => r->XYShape.T.makeFromZipped->E.R2.errMap(XYShape.Error.toString))
|
)
|
||||||
|
->Ok
|
||||||
|
->E.R.bind(r => r->XYShape.T.makeFromZipped->E.R2.errMap(XYShape.Error.toString))
|
||||||
->E.R2.fmap(r => Reducer_T.IEvDistribution(PointSet(r->xyShapeToPointSetDist)))
|
->E.R2.fmap(r => Reducer_T.IEvDistribution(PointSet(r->xyShapeToPointSetDist)))
|
||||||
}
|
|
||||||
| _ => impossibleError->Reducer_ErrorValue.toException
|
| _ => impossibleError->Reducer_ErrorValue.toException
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,9 +115,8 @@ let libaryBase = [
|
||||||
~inputs=[FRTypeArray(FRTypeNumber)],
|
~inputs=[FRTypeArray(FRTypeNumber)],
|
||||||
~run=(inputs, _, _) => {
|
~run=(inputs, _, _) => {
|
||||||
let sampleSet =
|
let sampleSet =
|
||||||
inputs->Prepare.ToTypedArray.numbers |> E.R2.bind(r =>
|
inputs->Prepare.ToTypedArray.numbers
|
||||||
SampleSetDist.make(r)->E.R2.errMap(_ => "AM I HERE? WHYERE AMI??")
|
|> E.R2.bind(r => SampleSetDist.make(r)->E.R2.errMap(_ => "AM I HERE? WHYERE AMI??"))
|
||||||
)
|
|
||||||
sampleSet
|
sampleSet
|
||||||
->E.R2.fmap(Wrappers.sampleSet)
|
->E.R2.fmap(Wrappers.sampleSet)
|
||||||
->E.R2.fmap(Wrappers.evDistribution)
|
->E.R2.fmap(Wrappers.evDistribution)
|
||||||
|
|
|
@ -31,14 +31,13 @@ let library = [
|
||||||
]),
|
]),
|
||||||
],
|
],
|
||||||
~run=(inputs, environment, _) => {
|
~run=(inputs, environment, _) => {
|
||||||
switch FunctionRegistry_Helpers.Prepare.ToValueArray.Record.threeArgs(inputs, ("estimate", "answer", "prior")) {
|
switch FunctionRegistry_Helpers.Prepare.ToValueArray.Record.threeArgs(
|
||||||
|
inputs,
|
||||||
|
("estimate", "answer", "prior"),
|
||||||
|
) {
|
||||||
| Ok([IEvDistribution(estimate), IEvDistribution(d), IEvDistribution(prior)]) =>
|
| Ok([IEvDistribution(estimate), IEvDistribution(d), IEvDistribution(prior)]) =>
|
||||||
runScoring(estimate, Score_Dist(d), Some(prior), environment)
|
runScoring(estimate, Score_Dist(d), Some(prior), environment)
|
||||||
| Ok([
|
| Ok([IEvDistribution(estimate), IEvNumber(d), IEvDistribution(prior)]) =>
|
||||||
IEvDistribution(estimate),
|
|
||||||
IEvNumber(d),
|
|
||||||
IEvDistribution(prior),
|
|
||||||
]) =>
|
|
||||||
runScoring(estimate, Score_Scalar(d), Some(prior), environment)
|
runScoring(estimate, Score_Scalar(d), Some(prior), environment)
|
||||||
| Error(e) => Error(e->FunctionRegistry_Helpers.wrapError)
|
| Error(e) => Error(e->FunctionRegistry_Helpers.wrapError)
|
||||||
| _ => Error(FunctionRegistry_Helpers.impossibleError)
|
| _ => Error(FunctionRegistry_Helpers.impossibleError)
|
||||||
|
@ -50,7 +49,10 @@ let library = [
|
||||||
~name="logScore",
|
~name="logScore",
|
||||||
~inputs=[FRTypeRecord([("estimate", FRTypeDist), ("answer", FRTypeDistOrNumber)])],
|
~inputs=[FRTypeRecord([("estimate", FRTypeDist), ("answer", FRTypeDistOrNumber)])],
|
||||||
~run=(inputs, environment, _) => {
|
~run=(inputs, environment, _) => {
|
||||||
switch FunctionRegistry_Helpers.Prepare.ToValueArray.Record.twoArgs(inputs, ("estimate", "answer")) {
|
switch FunctionRegistry_Helpers.Prepare.ToValueArray.Record.twoArgs(
|
||||||
|
inputs,
|
||||||
|
("estimate", "answer"),
|
||||||
|
) {
|
||||||
| Ok([IEvDistribution(estimate), IEvDistribution(d)]) =>
|
| Ok([IEvDistribution(estimate), IEvDistribution(d)]) =>
|
||||||
runScoring(estimate, Score_Dist(d), None, environment)
|
runScoring(estimate, Score_Dist(d), None, environment)
|
||||||
| Ok([IEvDistribution(estimate), IEvNumber(d)]) =>
|
| Ok([IEvDistribution(estimate), IEvNumber(d)]) =>
|
||||||
|
|
|
@ -83,19 +83,20 @@ module FRType = {
|
||||||
| (FRTypeNumeric, IEvNumber(_)) => true
|
| (FRTypeNumeric, IEvNumber(_)) => true
|
||||||
| (FRTypeNumeric, IEvDistribution(Symbolic(#Float(_)))) => true
|
| (FRTypeNumeric, IEvDistribution(Symbolic(#Float(_)))) => true
|
||||||
| (FRTypeLambda, IEvLambda(_)) => true
|
| (FRTypeLambda, IEvLambda(_)) => true
|
||||||
| (FRTypeArray(intendedType), IEvArray(elements)) => {
|
| (FRTypeArray(intendedType), IEvArray(elements)) => elements->Belt.Array.every(v =>
|
||||||
elements->Belt.Array.every(v => matchWithValue(intendedType, v))
|
matchWithValue(intendedType, v)
|
||||||
}
|
)
|
||||||
| (FRTypeDict(r), IEvRecord(map)) =>
|
| (FRTypeDict(r), IEvRecord(map)) =>
|
||||||
map->Belt.Map.String.valuesToArray->Belt.Array.every(v => matchWithValue(r, v))
|
map->Belt.Map.String.valuesToArray->Belt.Array.every(v => matchWithValue(r, v))
|
||||||
| (FRTypeRecord(recordParams), IEvRecord(map)) => {
|
| (FRTypeRecord(recordParams), IEvRecord(map)) => recordParams->Belt.Array.every(((
|
||||||
recordParams->Belt.Array.every(((name, input)) => {
|
name,
|
||||||
|
input,
|
||||||
|
)) => {
|
||||||
switch map->Belt.Map.String.get(name) {
|
switch map->Belt.Map.String.get(name) {
|
||||||
| Some(v) => matchWithValue(input, v)
|
| Some(v) => matchWithValue(input, v)
|
||||||
| None => false
|
| None => false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
|
||||||
| _ => false
|
| _ => false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,8 +105,7 @@ module FRType = {
|
||||||
if !isSameLength {
|
if !isSameLength {
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
E.A.zip(inputs, args)
|
E.A.zip(inputs, args)->Belt.Array.every(((input, arg)) => matchWithValue(input, arg))
|
||||||
->Belt.Array.every(((input, arg)) => matchWithValue(input, arg))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,8 +108,10 @@ module Prepare = {
|
||||||
}
|
}
|
||||||
|
|
||||||
module Record = {
|
module Record = {
|
||||||
let twoDistOrNumber = (values: ts, labels: (string, string)): result<(frValueDistOrNumber, frValueDistOrNumber), err> =>
|
let twoDistOrNumber = (values: ts, labels: (string, string)): result<
|
||||||
values->ToValueArray.Record.twoArgs(labels)->E.R.bind(twoDistOrNumber)
|
(frValueDistOrNumber, frValueDistOrNumber),
|
||||||
|
err,
|
||||||
|
> => values->ToValueArray.Record.twoArgs(labels)->E.R.bind(twoDistOrNumber)
|
||||||
|
|
||||||
let twoDist = (values: ts, labels: (string, string)): result<
|
let twoDist = (values: ts, labels: (string, string)): result<
|
||||||
(DistributionTypes.genericDist, DistributionTypes.genericDist),
|
(DistributionTypes.genericDist, DistributionTypes.genericDist),
|
||||||
|
|
|
@ -188,7 +188,6 @@ let linkDependencies = (project: t, sourceId: string): Reducer_T.namespace => {
|
||||||
acc->Reducer_Namespace.set(
|
acc->Reducer_Namespace.set(
|
||||||
variable,
|
variable,
|
||||||
project->getBindings(includeFile)->Reducer_Namespace.toRecord,
|
project->getBindings(includeFile)->Reducer_Namespace.toRecord,
|
||||||
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user