Minor cleanup

This commit is contained in:
Ozzie Gooen 2022-06-09 06:34:31 -07:00
parent b48a0575d9
commit 1acd4fc259
2 changed files with 13 additions and 9 deletions

View File

@ -12,6 +12,8 @@ module Wrappers = {
let symbolicEvDistribution = r => r->DistributionTypes.Symbolic->evDistribution let symbolicEvDistribution = r => r->DistributionTypes.Symbolic->evDistribution
} }
let getOrError = (a, g) => E.A.get(a, g) |> E.O.toResult(impossibleError)
module Prepare = { module Prepare = {
type t = frValue type t = frValue
type ts = array<frValue> type ts = array<frValue>
@ -113,12 +115,12 @@ module Prepare = {
let numbers = (inputs: ts): result<array<float>, err> => { let numbers = (inputs: ts): result<array<float>, err> => {
let openNumbers = (elements: array<t>) => let openNumbers = (elements: array<t>) =>
elements->E.A2.fmap(oneNumber)->E.A.R.firstErrorOrOpen elements->E.A2.fmap(oneNumber)->E.A.R.firstErrorOrOpen
inputs->E.A.unsafe_get(0)->ToValueArray.Array.openA->E.R.bind(openNumbers) inputs->getOrError(0)->E.R.bind(ToValueArray.Array.openA)->E.R.bind(openNumbers)
} }
let dicts = (inputs: ts): Belt.Result.t<array<Js.Dict.t<frValue>>, err> => { let dicts = (inputs: ts): Belt.Result.t<array<Js.Dict.t<frValue>>, err> => {
let openDicts = (elements: array<t>) => elements->E.A2.fmap(oneDict)->E.A.R.firstErrorOrOpen let openDicts = (elements: array<t>) => elements->E.A2.fmap(oneDict)->E.A.R.firstErrorOrOpen
inputs->E.A.unsafe_get(0)->ToValueArray.Array.openA->E.R.bind(openDicts) inputs->getOrError(0)->E.R.bind(ToValueArray.Array.openA)->E.R.bind(openDicts)
} }
} }
} }
@ -253,8 +255,10 @@ module ArrayNumberDist = {
module NumberToNumber = { module NumberToNumber = {
let make = (name, fn) => let make = (name, fn) =>
FnDefinition.make(~name, ~inputs=[FRTypeNumber], ~run=(inputs, _) => { FnDefinition.make(~name, ~inputs=[FRTypeNumber], ~run=(inputs, _) => {
let num = inputs
inputs->E.A.unsafe_get(0)->Prepare.oneNumber->E.R2.fmap(fn)->E.R2.fmap(Wrappers.evNumber) ->getOrError(0)
num ->E.R.bind(Prepare.oneNumber)
->E.R2.fmap(fn)
->E.R2.fmap(Wrappers.evNumber)
}) })
} }

View File

@ -31,7 +31,7 @@ module Declaration = {
} }
let inputsTodist = (inputs: array<FunctionRegistry_Core.frValue>, makeDist) => { let inputsTodist = (inputs: array<FunctionRegistry_Core.frValue>, makeDist) => {
let array = inputs->E.A.unsafe_get(0)->Prepare.ToValueArray.Array.openA let array = inputs->getOrError(0)->E.R.bind(Prepare.ToValueArray.Array.openA)
let xyCoords = let xyCoords =
array->E.R.bind(xyCoords => array->E.R.bind(xyCoords =>
xyCoords xyCoords
@ -72,7 +72,7 @@ let registry = [
~name="Declaration", ~name="Declaration",
~definitions=[ ~definitions=[
FnDefinition.make(~name="declareFn", ~inputs=[Declaration.frType], ~run=(inputs, _) => { FnDefinition.make(~name="declareFn", ~inputs=[Declaration.frType], ~run=(inputs, _) => {
inputs->E.A.unsafe_get(0)->Declaration.fromExpressionValue inputs->getOrError(0)->E.R.bind(Declaration.fromExpressionValue)
}), }),
], ],
), ),
@ -342,7 +342,7 @@ let registry = [
->E.A.R.firstErrorOrOpen ->E.A.R.firstErrorOrOpen
->E.R2.fmap(Js.Dict.fromArray) ->E.R2.fmap(Js.Dict.fromArray)
->E.R2.fmap(Wrappers.evRecord) ->E.R2.fmap(Wrappers.evRecord)
inputs->E.A.unsafe_get(0)->Prepare.ToValueArray.Array.arrayOfArrays inputs->getOrError(0)->E.R.bind(Prepare.ToValueArray.Array.arrayOfArrays)
|> E.R2.bind(convertInternalItems) |> E.R2.bind(convertInternalItems)
}), }),
], ],
@ -364,7 +364,7 @@ let registry = [
], ],
), ),
Function.make( Function.make(
~name="Range", ~name="upTo",
~definitions=[ ~definitions=[
FnDefinition.make(~name="upTo", ~inputs=[FRTypeNumber, FRTypeNumber], ~run=(inputs, _) => FnDefinition.make(~name="upTo", ~inputs=[FRTypeNumber, FRTypeNumber], ~run=(inputs, _) =>
inputs inputs