More refactors of |> to ->

This commit is contained in:
Ozzie Gooen 2022-03-29 15:47:32 -04:00
parent 539c7cf783
commit c158b4183b
3 changed files with 29 additions and 29 deletions

View File

@ -29,7 +29,7 @@ let normalize = (t: t) =>
| #SampleSet(_) => t
}
let operationToFloat = (toPointSet: toPointSetFn, fnName, t) => {
let operationToFloat = (t, toPointSet: toPointSetFn, fnName) => {
let symbolicSolution = switch t {
| #Symbolic(r) =>
switch SymbolicDist.T.operate(fnName, r) {
@ -83,10 +83,10 @@ module Truncate = {
}
let run = (
t: t,
toPointSet: toPointSetFn,
leftCutoff: option<float>,
rightCutoff: option<float>,
t: t,
): result<t, error> => {
let doesNotNeedCutoff = E.O.isNone(leftCutoff) && E.O.isNone(rightCutoff)
if doesNotNeedCutoff {
@ -95,7 +95,7 @@ module Truncate = {
switch trySymbolicSimplification(leftCutoff, rightCutoff, t) {
| Some(r) => Ok(r)
| None =>
toPointSet(t) |> E.R.fmap(t =>
toPointSet(t)->E.R.fmap2(t =>
#PointSet(PointSetDist.T.truncate(leftCutoff, rightCutoff, t))
)
}
@ -134,7 +134,7 @@ module AlgebraicCombination = {
t1: t,
t2: t,
) =>
E.R.merge(toPointSet(t1), toPointSet(t2)) |> E.R.fmap(((a, b)) =>
E.R.merge(toPointSet(t1), toPointSet(t2))->E.R.fmap2(((a, b)) =>
PointSetDist.combineAlgebraically(operation, a, b)
)
@ -145,8 +145,8 @@ module AlgebraicCombination = {
t2: t,
) => {
let operation = Operation.Algebraic.toFn(operation)
E.R.merge(toSampleSet(t1), toSampleSet(t2)) |> E.R.fmap(((a, b)) => {
Belt.Array.zip(a, b) |> E.A.fmap(((a, b)) => operation(a, b))
E.R.merge(toSampleSet(t1), toSampleSet(t2)) -> E.R.fmap2(((a, b)) => {
Belt.Array.zip(a, b) -> E.A.fmap2(((a, b)) => operation(a, b))
})
}
@ -155,7 +155,7 @@ module AlgebraicCombination = {
switch x {
| #Symbolic(#Float(_)) => 1
| #Symbolic(_) => 1000
| #PointSet(Discrete(m)) => m.xyShape |> XYShape.T.length
| #PointSet(Discrete(m)) => m.xyShape -> XYShape.T.length
| #PointSet(Mixed(_)) => 1000
| #PointSet(Continuous(_)) => 1000
| _ => 1000
@ -167,10 +167,10 @@ module AlgebraicCombination = {
: #CalculateWithConvolution
let run = (
t1: t,
toPointSet: toPointSetFn,
toSampleSet: toSampleSetFn,
algebraicOp,
t1: t,
t2: t,
): result<t, error> => {
switch tryAnalyticalSimplification(algebraicOp, t1, t2) {
@ -190,7 +190,7 @@ module AlgebraicCombination = {
let algebraicCombination = AlgebraicCombination.run
//TODO: Add faster pointwiseCombine fn
let pointwiseCombination = (toPointSet: toPointSetFn, operation, t2: t, t1: t): result<
let pointwiseCombination = (t1: t, toPointSet: toPointSetFn, operation, t2: t): result<
t,
error,
> => {
@ -202,10 +202,10 @@ let pointwiseCombination = (toPointSet: toPointSetFn, operation, t2: t, t1: t):
}
let pointwiseCombinationFloat = (
t: t,
toPointSet: toPointSetFn,
operation: GenericDist_Types.Operation.arithmeticOperation,
f: float,
t: t,
): result<t, error> => {
switch operation {
| #Add | #Subtract => Error(GenericDist_Types.DistributionVerticalShiftIsInvalid)
@ -227,9 +227,9 @@ let pointwiseCombinationFloat = (
//Note: The result should always cumulatively sum to 1.
let mixture = (
values: array<(t, float)>,
scaleMultiply: scaleMultiplyFn,
pointwiseAdd: pointwiseAddFn,
values: array<(t, float)>,
) => {
if E.A.length(values) == 0 {
Error(GenericDist_Types.Other("mixture must have at least 1 element"))

View File

@ -13,32 +13,32 @@ let toString: t => string
let normalize: t => t
let operationToFloat: (toPointSetFn, Operation.distToFloatOperation, t) => result<float, error>
let operationToFloat: (t, toPointSetFn, Operation.distToFloatOperation) => result<float, error>
let toPointSet: (t, int) => result<PointSetTypes.pointSetDist, error>
let truncate: (toPointSetFn, option<float>, option<float>, t) => result<t, error>
let truncate: (t, toPointSetFn, option<float>, option<float>) => result<t, error>
let algebraicCombination: (
t,
toPointSetFn,
toSampleSetFn,
GenericDist_Types.Operation.arithmeticOperation,
t,
t,
) => result<t, error>
let pointwiseCombination: (
t,
toPointSetFn,
GenericDist_Types.Operation.arithmeticOperation,
t,
t,
) => result<t, error>
let pointwiseCombinationFloat: (
t,
toPointSetFn,
GenericDist_Types.Operation.arithmeticOperation,
float,
t,
) => result<t, error>
let mixture: (scaleMultiplyFn, pointwiseAddFn, array<(t, float)>) => result<t, error>
let mixture: (array<(t, float)>, scaleMultiplyFn, pointwiseAddFn) => result<t, error>

View File

@ -93,7 +93,7 @@ let rec run = (extra, fnName: operation): outputType => {
let fromDistFn = (subFn: GenericDist_Types.Operation.fromDist, dist: genericDist) =>
switch subFn {
| #toFloat(fnName) =>
GenericDist.operationToFloat(toPointSet, fnName, dist)->E.R.fmap2(r => #Float(r))->fromResult
GenericDist.operationToFloat(dist, toPointSet, fnName)->E.R.fmap2(r => #Float(r))->fromResult
| #toString => dist->GenericDist.toString->(r => #String(r))
| #toDist(#consoleLog) => {
Js.log2("Console log requested: ", dist)
@ -101,7 +101,7 @@ let rec run = (extra, fnName: operation): outputType => {
}
| #toDist(#normalize) => dist->GenericDist.normalize->(r => #Dist(r))
| #toDist(#truncate(left, right)) =>
dist |> GenericDist.truncate(toPointSet, left, right) |> E.R.fmap(r => #Dist(r)) |> fromResult
dist->GenericDist.truncate(toPointSet, left, right)->E.R.fmap2(r => #Dist(r))->fromResult
| #toDist(#toPointSet) =>
dist->GenericDist.toPointSet(xyPointLength)->E.R.fmap2(r => #Dist(#PointSet(r)))->fromResult
| #toDist(#toSampleSet(n)) =>
@ -109,26 +109,26 @@ let rec run = (extra, fnName: operation): outputType => {
| #toDistCombination(#Algebraic, _, #Float(_)) => #Error(NotYetImplemented)
| #toDistCombination(#Algebraic, operation, #Dist(dist2)) =>
dist
|> GenericDist.algebraicCombination(toPointSet, toSampleSet, operation, dist2)
|> E.R.fmap(r => #Dist(r))
|> fromResult
->GenericDist.algebraicCombination(toPointSet, toSampleSet, operation, dist2)
->E.R.fmap2(r => #Dist(r))
->fromResult
| #toDistCombination(#Pointwise, operation, #Dist(dist2)) =>
dist
|> GenericDist.pointwiseCombination(toPointSet, operation, dist2)
|> E.R.fmap(r => #Dist(r))
|> fromResult
->GenericDist.pointwiseCombination(toPointSet, operation, dist2)
->E.R.fmap2(r => #Dist(r))
->fromResult
| #toDistCombination(#Pointwise, operation, #Float(f)) =>
dist
|> GenericDist.pointwiseCombinationFloat(toPointSet, operation, f)
|> E.R.fmap(r => #Dist(r))
|> fromResult
->GenericDist.pointwiseCombinationFloat(toPointSet, operation, f)
->E.R.fmap2(r => #Dist(r))
->fromResult
}
switch fnName {
| #fromDist(subFn, dist) => fromDistFn(subFn, dist)
| #fromFloat(subFn, float) => reCall(~fnName=#fromDist(subFn, GenericDist.fromFloat(float)), ())
| #mixture(dists) =>
GenericDist.mixture(scaleMultiply, pointwiseAdd, dists)->E.R.fmap2(r => #Dist(r))->fromResult
dists->GenericDist.mixture(scaleMultiply, pointwiseAdd)->E.R.fmap2(r => #Dist(r))->fromResult
}
}