From b5b29e99d6a170bba05aba7817e8caed05317187 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Wed, 5 Feb 2020 22:14:59 +0000 Subject: [PATCH] Minor fix --- src/Test2.bs.js | 30 ++++++++++++++++++++---------- src/Test2.re | 42 +++++++++++++++++++++++++++--------------- 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/Test2.bs.js b/src/Test2.bs.js index 5109f18d..37556fb2 100644 --- a/src/Test2.bs.js +++ b/src/Test2.bs.js @@ -16,34 +16,44 @@ var $$Math = { divide: divide }; -function run(company, year, param) { +function sharesOutstanding(price, marketCap) { + if (price !== undefined && marketCap !== undefined) { + return divide(marketCap, price); + } + +} + +function run(company, year, param, otherSettings) { var match = company.currentPrice; + var match$1 = company.marketCap; switch (param) { case /* SHARE_PRICE */0 : if (match !== undefined && year > 2019 && year < 2030) { - var diffYears = year - 2020 | 0; + var diffYears = year - otherSettings.currentYear | 0; return normal(match, diffYears * 0.1); } else { return ; } case /* SHARES_OUTSTANDING */1 : if (year > 2019 && year < 2030) { - var price = run(company, year, /* SHARE_PRICE */0); - var marketCap = run(company, year, /* MARKET_CAP */2); - if (price !== undefined && marketCap !== undefined) { - return divide(marketCap, price); - } else { - return ; - } + var price = run(company, year, /* SHARE_PRICE */0, otherSettings); + var marketCap = run(company, year, /* MARKET_CAP */2, otherSettings); + return sharesOutstanding(price, marketCap); } else { return ; } case /* MARKET_CAP */2 : - return ; + if (match$1 !== undefined && year > 2019 && year < 2030) { + var diffYears$1 = year - otherSettings.currentYear | 0; + return normal(match$1, diffYears$1 * 0.1); + } else { + return ; + } } } exports.$$Math = $$Math; +exports.sharesOutstanding = sharesOutstanding; exports.run = run; /* No side effect */ diff --git a/src/Test2.re b/src/Test2.re index 0746738d..9e30a5a4 100644 --- a/src/Test2.re +++ b/src/Test2.re @@ -19,25 +19,37 @@ type param = type company = { name: string, currentPrice: option(float), + marketCap: option(float), }; -let rec run = (company: company, year: int, param: param) => { - switch (param, year, company.currentPrice) { - | (SHARE_PRICE, year, Some(price)) when year > 2019 && year < 2030 => - let diffYears = year - 2020; +type otherSettings = {currentYear: int}; + +let sharesOutstanding = (price, marketCap) => + switch (price, marketCap) { + | (Some(price), Some(marketCap)) => Some(Math.divide(marketCap, price)) + | _ => None + }; + +let rec run = + ( + company: company, + year: int, + param: param, + otherSettings: otherSettings, + ) => { + switch (param, year, company.currentPrice, company.marketCap) { + | (SHARE_PRICE, year, Some(price), _) when year > 2019 && year < 2030 => + let diffYears = year - otherSettings.currentYear; let diffPerYear = 0.1; Some(Math.normal(price, float_of_int(diffYears) *. diffPerYear)); - - | (SHARES_OUTSTANDING, year, _) when year > 2019 && year < 2030 => - let price = run(company, year, SHARE_PRICE); - let marketCap = run(company, year, MARKET_CAP); - switch (price, marketCap) { - | (Some(price), Some(marketCap)) => - Some(Math.divide(marketCap, price)) - - | _ => None - }; - + | (MARKET_CAP, year, _, Some(price)) when year > 2019 && year < 2030 => + let diffYears = year - otherSettings.currentYear; + let diffPerYear = 0.1; + Some(Math.normal(price, float_of_int(diffYears) *. diffPerYear)); + | (SHARES_OUTSTANDING, year, _, _) when year > 2019 && year < 2030 => + let price = run(company, year, SHARE_PRICE, otherSettings); + let marketCap = run(company, year, MARKET_CAP, otherSettings); + sharesOutstanding(price, marketCap); | _ => None }; }; \ No newline at end of file