tweak: format

This commit is contained in:
NunoSempere 2022-09-05 16:08:06 +02:00
parent 8f8ca02730
commit 9551aae634

View File

@ -214,12 +214,13 @@ module Internals = {
let increment = funds /. numDivisions let increment = funds /. numDivisions
let arrayOfIncrements = Belt.Array.makeBy(numDivisionsInt, _ => increment) let arrayOfIncrements = Belt.Array.makeBy(numDivisionsInt, _ => increment)
let findBiggestElementIndex = (xs) => E.A.reducei(xs, 0, (acc, newElement, index) => { let findBiggestElementIndex = xs =>
switch(newElement > xs[acc]){ E.A.reducei(xs, 0, (acc, newElement, index) => {
switch newElement > xs[acc] {
| true => index | true => index
| false => acc | false => acc
} }
}) })
let initAccumulator: diminishingReturnsAccumulator = Ok({ let initAccumulator: diminishingReturnsAccumulator = Ok({
optimalAllocations: [0.0, 0.0], optimalAllocations: [0.0, 0.0],
currentMarginalReturns: E.A.R.firstErrorOrOpen([ currentMarginalReturns: E.A.R.firstErrorOrOpen([
@ -231,43 +232,45 @@ module Internals = {
acc, acc,
newIncrement, newIncrement,
) => { ) => {
switch(acc){ switch acc {
| Ok(accInner) => { | Ok(accInner) => {
let oldMarginalReturnsWrapped = accInner.currentMarginalReturns let oldMarginalReturnsWrapped = accInner.currentMarginalReturns
let newAccWrapped = switch(oldMarginalReturnsWrapped){ let newAccWrapped = switch oldMarginalReturnsWrapped {
| Ok(oldMarginalReturns) => { | Ok(oldMarginalReturns) => {
let indexOfBiggestDMR = findBiggestElementIndex(oldMarginalReturns) let indexOfBiggestDMR = findBiggestElementIndex(oldMarginalReturns)
let newOptimalAllocations = Belt.Array.copy(accInner.optimalAllocations) let newOptimalAllocations = Belt.Array.copy(accInner.optimalAllocations)
let newOptimalAllocationsi = let newOptimalAllocationsi = newOptimalAllocations[indexOfBiggestDMR] +. newIncrement
newOptimalAllocations[indexOfBiggestDMR] +. newIncrement
newOptimalAllocations[indexOfBiggestDMR] = newOptimalAllocationsi newOptimalAllocations[indexOfBiggestDMR] = newOptimalAllocationsi
let lambdai = indexOfBiggestDMR == 0 ? lambda1: lambda2 // to do: generalize let lambdai = indexOfBiggestDMR == 0 ? lambda1 : lambda2 // to do: generalize
let newMarginalResultsLambdai = applyFunctionAtFloatToFloatOption(lambdai, newOptimalAllocationsi) let newMarginalResultsLambdai = applyFunctionAtFloatToFloatOption(
let newCurrentMarginalReturns = switch(newMarginalResultsLambdai){ lambdai,
| Ok(value) => { newOptimalAllocationsi,
let result = Belt.Array.copy(oldMarginalReturns) )
result[indexOfBiggestDMR] = value let newCurrentMarginalReturns = switch newMarginalResultsLambdai {
Ok(result) | Ok(value) => {
let result = Belt.Array.copy(oldMarginalReturns)
result[indexOfBiggestDMR] = value
Ok(result)
} }
| Error(b) => Error(b) | Error(b) => Error(b)
} }
let newAcc: diminishingReturnsAccumulatorInner = { let newAcc: diminishingReturnsAccumulatorInner = {
optimalAllocations: newOptimalAllocations, optimalAllocations: newOptimalAllocations,
currentMarginalReturns: newCurrentMarginalReturns currentMarginalReturns: newCurrentMarginalReturns,
} }
Ok(newAcc) Ok(newAcc)
} }
| Error(b) => Error(b) | Error(b) => Error(b)
} }
newAccWrapped newAccWrapped
} }
| Error(b) => Error(b) | Error(b) => Error(b)
} }
/*let findSmaller = (_) => 0 /* let findSmaller = (_) => 0
let smallerDMR = let smallerDMR =
acc acc
*/ */
}) })
let optimalAllocationResult = switch optimalAllocationEndAccumulator { let optimalAllocationResult = switch optimalAllocationEndAccumulator {
| Ok(inner) => Ok(castArrayOfFloatsToInternalArrayOfInternals(inner.optimalAllocations)) | Ok(inner) => Ok(castArrayOfFloatsToInternalArrayOfInternals(inner.optimalAllocations))