diff --git a/packages/squiggle-lang/__tests__/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn_test.res b/packages/squiggle-lang/__tests__/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn_test.res index 682e1737..fb891bb3 100644 --- a/packages/squiggle-lang/__tests__/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn_test.res +++ b/packages/squiggle-lang/__tests__/Reducer/Reducer_Dispatch/Reducer_Dispatch_BuiltIn_test.res @@ -18,7 +18,7 @@ describe("builtin", () => { testEval("2>1", "Ok(true)") testEval("concat('a','b')", "Ok('ab')") testEval( - "addOne(t)=t+1; toInternalSampleArray(mapSamples(fromSamples([1,2,3,4,5,6]), addOne))", + "addOne(t)=t+1; toList(mapSamples(fromSamples([1,2,3,4,5,6]), addOne))", "Ok([2,3,4,5,6,7])", ) }) diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_Duration.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_Duration.res index 4e10dfa0..f6322fc4 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_Duration.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_Duration.res @@ -27,6 +27,8 @@ let dispatch = (call: EV.functionCall, _: DistributionOperation.env): option< EV.EvTimeDuration(DateTime.Duration.multiply(d1, d2))->Ok->Some | ("divide", [EvTimeDuration(d1), EvNumber(d2)]) => EV.EvTimeDuration(DateTime.Duration.divide(d1, d2))->Ok->Some + | ("divide", [EvTimeDuration(d1), EvTimeDuration(d2)]) => + EV.EvNumber(d1 /. d2)->Ok->Some | _ => None } } diff --git a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res index 872e8145..2b49439a 100644 --- a/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res +++ b/packages/squiggle-lang/src/rescript/ReducerInterface/ReducerInterface_GenericDistribution.res @@ -277,7 +277,7 @@ let dispatchToGenericOutput = ( Helpers.toDistFn(ToSampleSet(Belt.Int.fromFloat(float)), dist, ~env) | ("toSampleSet", [EvDistribution(dist)]) => Helpers.toDistFn(ToSampleSet(env.sampleCount), dist, ~env) - | ("toInternalSampleArray", [EvDistribution(SampleSet(dist))]) => + | ("toList", [EvDistribution(SampleSet(dist))]) => Some(FloatArray(SampleSetDist.T.get(dist))) | ("fromSamples", [EvArray(inputArray)]) => { let _wrapInputErrors = x => SampleSetDist.NonNumericInput(x) diff --git a/packages/website/docs/Api/Date.md b/packages/website/docs/Api/Date.md new file mode 100644 index 00000000..cd6c766d --- /dev/null +++ b/packages/website/docs/Api/Date.md @@ -0,0 +1,42 @@ +--- +sidebar_position: 1 +title: Date +--- + +### makeFromYear + +``` +Date.makeFromYear: (number) => date +``` + +```js +makeFromYear(2022.32); +``` + +### toString + +``` +toString: (date) => string +``` + +### subtract + +``` +subtract: (date, date) => duration +subtract: (date, duration) => date +``` + +```js +makeFromYear(2040) - makeFromYear(2020) // 20 years +makeFromYear(2040) - years(20) // 2020 +``` + +### add + +``` +add: (date, duration) => date +``` + +```js +makeFromYear(2022.32) + years(5); +``` diff --git a/packages/website/docs/Api/Dictionary.md b/packages/website/docs/Api/Dictionary.md index 162fbdd8..6d0a2cbf 100644 --- a/packages/website/docs/Api/Dictionary.md +++ b/packages/website/docs/Api/Dictionary.md @@ -1,58 +1,58 @@ --- -sidebar_position: 1 +sidebar_position: 2 title: Dictionary --- - -### toString +### toList ``` -toString: (dict<'a>) => string +Dict.toList: (dict<'a>) => list> ``` - - -### get -``` -Dict.get: (dict<'a>, string) => a +```js +Dict.toList({foo: 3, bar: 20}) // [["foo", 3], ["bar", 20]] ``` - - -### set +### fromList ``` -Dict.set: (dict<'a>, string, a) => a +Dict.fromList: (list>) => dict<'a> ``` - - - -### toPairs +```js +Dict.fromList([["foo", 3], ["bar", 20]]) // {foo: 3, bar: 20} ``` -Dict.toPairs: (dict<'a>) => list> -``` - - ### keys ``` Dict.keys: (dict<'a>) => list ``` - - +```js +Dict.keys({foo: 3, bar: 20}) // ["foo", "bar"] +``` ### values ``` Dict.values: (dict<'a>) => list<'a> ``` - - +```js +Dict.values({foo: 3, bar: 20}) // [3,20] +``` ### merge ``` Dict.merge: (dict<'a>, dict<'b>) => dict<'a|b> ``` - +```js +first = {a: 1, b: 2} +snd = {b: 3, c: 5} +Dict.merge(first, snd) // {a: 1, b: 3, c: 5} +``` ### mergeMany ``` Dict.mergeMany: (list>) => dict<'a> +``` + +```js +first = {a: 1, b: 2} +snd = {b: 3, c: 5} +Dict.mergeMany([first, snd]) // {a: 1, b: 3, c: 5} ``` \ No newline at end of file diff --git a/packages/website/docs/Api/DistGeneric.mdx b/packages/website/docs/Api/DistGeneric.mdx index ddbd8de3..5b3869f2 100644 --- a/packages/website/docs/Api/DistGeneric.mdx +++ b/packages/website/docs/Api/DistGeneric.mdx @@ -1,32 +1,33 @@ --- -sidebar_position: 2 +sidebar_position: 3 title: Distribution --- -import TOCInline from '@theme/TOCInline'; + +import TOCInline from "@theme/TOCInline"; -## Creation +## Distribution Creation ### Normal Distribution **Definitions** ```javascript -normal(frValueDistOrNumber, frValueDistOrNumber); +normal: (frValueDistOrNumber, frValueDistOrNumber); ``` ```javascript -normal(dict<{p5: frValueDistOrNumber, p95: frValueDistOrNumber}>) +normal: (dict<{p5: frValueDistOrNumber, p95: frValueDistOrNumber}>) ``` ```javascript -normal(dict<{mean: frValueDistOrNumber, stdev: frValueDistOrNumber}>) +normal: (dict<{mean: frValueDistOrNumber, stdev: frValueDistOrNumber}>) ``` **Examples** -```javascript +```js normal(5, 1); normal({ p5: 4, p95: 10 }); normal({ mean: 5, stdev: 2 }); @@ -37,15 +38,15 @@ normal({ mean: 5, stdev: 2 }); **Definitions** ```javascript -lognormal(frValueDistOrNumber, frValueDistOrNumber); +lognormal: (frValueDistOrNumber, frValueDistOrNumber); ``` ```javascript -lognormal(dict<{p5: frValueDistOrNumber, p95: frValueDistOrNumber}>) +lognormal: (dict<{p5: frValueDistOrNumber, p95: frValueDistOrNumber}>) ``` ```javascript -lognormal(dict<{mean: frValueDistOrNumber, stdev: frValueDistOrNumber}>) +lognormal: (dict<{mean: frValueDistOrNumber, stdev: frValueDistOrNumber}>) ``` **Examples** @@ -61,7 +62,7 @@ lognormal({ mean: 5, stdev: 2 }); **Definitions** ```javascript -uniform(frValueDistOrNumber, frValueDistOrNumber); +uniform: (frValueDistOrNumber, frValueDistOrNumber); ``` **Examples** @@ -75,7 +76,7 @@ uniform(10, 12); **Definitions** ```javascript -beta(frValueDistOrNumber, frValueDistOrNumber); +beta: (frValueDistOrNumber, frValueDistOrNumber); ``` **Examples** @@ -89,7 +90,7 @@ beta(20, 25); **Definitions** ```javascript -cauchy(frValueDistOrNumber, frValueDistOrNumber); +cauchy: (frValueDistOrNumber, frValueDistOrNumber); ``` **Examples** @@ -103,7 +104,7 @@ cauchy(5, 1); **Definitions** ```javascript -gamma(frValueDistOrNumber, frValueDistOrNumber); +gamma: (frValueDistOrNumber, frValueDistOrNumber); ``` **Examples** @@ -117,7 +118,7 @@ gamma(5, 1); **Definitions** ```javascript -logistic(frValueDistOrNumber, frValueDistOrNumber); +logistic: (frValueDistOrNumber, frValueDistOrNumber); ``` **Examples** @@ -131,7 +132,7 @@ gamma(5, 1); **Definitions** ```javascript -to(frValueDistOrNumber, frValueDistOrNumber); +to: (frValueDistOrNumber, frValueDistOrNumber); ``` ```javascript @@ -151,7 +152,7 @@ to(5,10) **Definitions** ```javascript -exponential(frValueDistOrNumber); +exponential: (frValueDistOrNumber); ``` **Examples** @@ -165,7 +166,7 @@ exponential(2); **Definitions** ```javascript -bernoulli(frValueDistOrNumber); +bernoulli: (frValueDistOrNumber); ``` **Examples** @@ -181,7 +182,7 @@ Converts a set of points to a continuous distribution **Definitions** ```javascript -toContinuousPointSet(array>) +toContinuousPointSet: (array>) ``` **Examples** @@ -202,7 +203,7 @@ Converts a set of points to a discrete distribution **Definitions** ```javascript -toDiscretePointSet(array>) +toDiscretePointSet: (array>) ``` **Examples** @@ -216,41 +217,19 @@ toDiscretePointSet([ ]); ``` -### Declaration (Continuous Function) - -Adds metadata to a function of the input ranges. Works now for numeric and date inputs. This is useful when making predictions. It allows you to limit the domain that your prediction will be used and scored within. - -**Definitions** - -```javascript -declareFn(dict<{fn: lambda, inputs: array>}>) -``` - -**Examples** - -```javascript -declareFn({ - fn: {|a,b| a }, - inputs: [ - {min: 0, max: 100}, - {min: 30, max: 50} - ] -}) -``` - ## Functions - ### mixture ```javascript -(...distributionLike, weights:list):distribution +mixture: (...distributionLike, weights:list):distribution ``` **Examples** ```javascript mixture(normal(5, 1), normal(10, 1)); +mx(normal(5, 1), normal(10, 1), [0.3, 0.7]); ``` ### sample @@ -258,7 +237,7 @@ mixture(normal(5, 1), normal(10, 1)); Get one random sample from the distribution ```javascript -(distribution):number +sample(distribution):number ``` **Examples** @@ -272,13 +251,13 @@ sample(normal(5, 2)); Get n random samples from the distribution ```javascript -(distribution, number):list +sampleN: (distribution, number):list ``` **Examples** ```javascript -sample(normal(5, 2), 100); +sample: (normal(5, 2), 100); ``` ### mean @@ -286,73 +265,61 @@ sample(normal(5, 2), 100); Get the distribution mean ```javascript -(distribution):number +mean: (distribution):number ``` **Examples** ```javascript -mean(normal(5, 2)); +mean: (normal(5, 2)); ``` ### stdev ```javascript -(distribution):number +stdev: (distribution):number ``` ### variance ```javascript -(distribution):number +variance: (distribution):number ``` ### mode ```javascript -(distribution):number +mode: (distribution):number ``` ### cdf ```javascript -(distribution, number):number +cdf: (distribution, number):number ``` **Examples** ```javascript -cdf(normal(5, 2), 3); +cdf: (normal(5, 2), 3); ``` ### pdf ```javascript -(distribution, number):number +pdf: (distribution, number):number ``` **Examples** ```javascript -pdf(normal(5, 2), 3); -``` - -### pmf - -```javascript -(distribution, number):number -``` - -**Examples** - -```javascript -pmf(bernoulli(0.3), 0); // 0.7 +pdf: (normal(5, 2), 3); ``` ### inv ```javascript -(distribution, number):number +inv: (distribution, number):number ``` **Examples** @@ -366,7 +333,7 @@ inv(normal(5, 2), 0.5); Converts a distribution to the pointSet format ```javascript -(distribution):pointSetDistribution +toPointSet: (distribution):pointSetDistribution ``` **Examples** @@ -380,13 +347,13 @@ toPointSet(normal(5, 2)); Converts a distribution to the sampleSet format, with n samples ```javascript -(distribution,n):sampleSetribution +toSampleSet: (distribution,number):sampleSetDistribution ``` **Examples** ```javascript -toSampleSet(normal(5, 2)); +toSampleSet(normal(5, 2), 1000); ``` ### truncateLeft @@ -394,7 +361,7 @@ toSampleSet(normal(5, 2)); Truncates the left side of a distribution. Returns either a pointSet distribution or a symbolic distribution. ```javascript -(distribution, l:number, {normalize: boolean=true}):distribution +truncateLeft: (distribution, l:number):distribution ``` **Examples** @@ -408,7 +375,7 @@ truncateLeft(normal(5, 2), 3); Truncates the right side of a distribution. Returns either a pointSet distribution or a symbolic distribution. ```javascript -(distribution, r:number, {normalize: boolean=true}):distribution +truncateRight: (distribution, r:number):distribution ``` **Examples** @@ -424,7 +391,7 @@ truncateLeft(normal(5, 2), 6); Kullback–Leibler divergence between two distributions ```javascript -(distribution, distribution):number +klDivergence: (distribution, distribution):number ``` **Examples** @@ -433,24 +400,12 @@ Kullback–Leibler divergence between two distributions klDivergence(normal(5, 2), normal(5, 4)); // returns 0.57 ``` -### logScore - -```javascript -({estimate: distribution, prior?: distribution, answer: distribution|number}):number -``` - -**Examples** - -```javascript -logScore({ estimate: normal(5, 2), prior: normal(5.5, 4), answer: 2.3 }); -``` - ## Display ### toString ```javascript -(distribution):string +: (distribution):string ``` **Examples** @@ -464,7 +419,7 @@ toString(normal(5, 2)); Produce a sparkline of length n ```javascript -(distribution, n=20):string +toSparkline: (distribution, n=20):string ``` **Examples** @@ -478,7 +433,7 @@ toSparkline(normal(5, 2), 10); Prints the value of the distribution to the Javascript console, then returns the distribution. ```javascript -(distribution):distribution +inspect: (distribution):distribution ``` **Examples** @@ -494,7 +449,7 @@ inspect(normal(5, 2)); Normalize a distribution. This means scaling it appropriately so that it's cumulative sum is equal to 1. ```javascript -(distribution):distribution +normalize: (distribution):distribution ``` **Examples** @@ -508,7 +463,7 @@ normalize(normal(5, 2)); Check of a distribution is normalized. Most distributions are typically normalized, but there are some commands that could produce non-normalized distributions. ```javascript -(distribution):bool +isNormalized: (distribution):bool ``` **Examples** @@ -522,7 +477,7 @@ isNormalized(normal(5, 2)); // returns true Get the sum of the integral of a distribution. If the distribution is normalized, this will be 1. ```javascript -(distribution):number +integralSum: (distribution):number ``` **Examples** @@ -531,158 +486,162 @@ Get the sum of the integral of a distribution. If the distribution is normalized integralSum(normal(5, 2)); ``` -## Algebra1 +## Algebraic Operations ### add ```javascript -(distributionLike, distributionLike): distribution +add: (distributionLike, distributionLike): distribution ``` ### sum ```javascript -(list): distribution +sum: (list): distribution ``` ### multiply ```javascript -(distributionLike, distributionLike): distribution +multiply: (distributionLike, distributionLike): distribution ``` ### product ```javascript -(list): distribution +product: (list): distribution ``` ### subtract ```javascript -(distributionLike, distributionLike): distribution +subtract: (distributionLike, distributionLike): distribution ``` ### divide ```javascript -(distributionLike, distributionLike): distribution +divide: (distributionLike, distributionLike): distribution ``` ### pow ```javascript -(distributionLike, distributionLike): distribution +pow: (distributionLike, distributionLike): distribution ``` ### exp ```javascript -(distributionLike, distributionLike): distribution +exp: (distributionLike, distributionLike): distribution ``` ### log ```javascript -(distributionLike, distributionLike): distribution +log: (distributionLike, distributionLike): distribution ``` ### log10 ```javascript -(distributionLike, distributionLike):distribution +log10: (distributionLike, distributionLike):distribution ``` ### unaryMinus ```javascript -(distribution):distribution +unaryMinus: (distribution):distribution ``` -## Algebra2 +## Pointwise Operations ### dotAdd ```javascript -(distributionLike, distributionLike): distribution -``` - -### dotSum - -```javascript -(list): distribution +dotAdd: (distributionLike, distributionLike): distribution ``` ### dotMultiply ```javascript -(distributionLike, distributionLike): distribution -``` - -### dotProduct - -```javascript -(list): distribution +dotMultiply: (distributionLike, distributionLike): distribution ``` ### dotSubtract ```javascript -(distributionLike, distributionLike): distribution +dotSubtract: (distributionLike, distributionLike): distribution ``` ### dotDivide ```javascript -(distributionLike, distributionLike): distribution +dotDivide: (distributionLike, distributionLike): distribution ``` ### dotPow ```javascript -(distributionLike, distributionLike): distribution +dotPow: (distributionLike, distributionLike): distribution ``` ### dotExp ```javascript -(distributionLike, distributionLike): distribution +dotExp: (distributionLike, distributionLike): distribution ``` -## Algebra3 +## Scale Operations ### scaleMultiply ```javascript -(distributionLike, distributionLike): distribution +scaleMultiply: (distributionLike, number): distribution ``` ### scalePow ```javascript -(distributionLike, distributionLike): distribution +scalePow: (distributionLike, number): distribution ``` ### scaleExp ```javascript -(distributionLike, distributionLike): distribution +scaleExp: (distributionLike, number): distribution ``` ### scaleLog ```javascript -(distributionLike, distributionLike): distribution +scaleLog: (distributionLike, number): distribution ``` ### scaleLog10 ```javascript -(distributionLike, distributionLike): distribution +scaleLog10: (distributionLike, number): distribution ``` -### scaleLogWithThreshold +## Special + +### Declaration (Continuous Function) + +Adds metadata to a function of the input ranges. Works now for numeric and date inputs. This is useful when making predictions. It allows you to limit the domain that your prediction will be used and scored within. ```javascript -(distributionLike, distributionLike, number): distribution +declareFn: (dict<{fn: lambda, inputs: array>}>) +``` + +**Examples** + +```javascript +declareFn({ + fn: {|a,b| a }, + inputs: [ + {min: 0, max: 100}, + {min: 30, max: 50} + ] +}) ``` diff --git a/packages/website/docs/Api/DistPointSet.md b/packages/website/docs/Api/DistPointSet.md index 0b638d88..f5336d24 100644 --- a/packages/website/docs/Api/DistPointSet.md +++ b/packages/website/docs/Api/DistPointSet.md @@ -1,5 +1,5 @@ --- -sidebar_position: 3 +sidebar_position: 4 title: Point Set Distribution --- @@ -8,23 +8,12 @@ title: Point Set Distribution PointSet.make: (distribution) => pointSetDist ``` - - ### makeContinuous ``` PointSet.makeContinuous: (list<{x: number, y: number}>) => pointSetDist ``` - - ### makeDiscrete ``` PointSet.makeDiscrete: (list<{x: number, y: number}>) => pointSetDist -``` - - - -### mapPoints -``` -PointSet.mapPoints: (pointSetDist, ({x:number, y:number} => {x:number, y:number})) => pointSetDist ``` \ No newline at end of file diff --git a/packages/website/docs/Api/DistSampleSet.md b/packages/website/docs/Api/DistSampleSet.md index b9a722d4..bf489ecf 100644 --- a/packages/website/docs/Api/DistSampleSet.md +++ b/packages/website/docs/Api/DistSampleSet.md @@ -1,5 +1,5 @@ --- -sidebar_position: 4 +sidebar_position: 5 title: Sample Set Distribution --- @@ -10,58 +10,31 @@ SampleSet.make: (() => number) => sampleSet SampleSet.make: (list) => sampleSet ``` - - -### kde -``` -SampleSet.kde: (sampleSet) => pointSetDist -``` - - - -### toEmpiricalPdf -``` -SampleSet.toEmpiricalPdf: (sampleSet) => pointSetDist -``` - - - ### map ``` SampleSet.map: (sampleSet, (number => number)) => sampleSet ``` - ### map2 ``` SampleSet.map2: (sampleSet, sampleSet, ((number, number) => number)) => sampleSet ``` - - ### map3 ``` SampleSet.map3: (sampleSet, sampleSet, sampleSet, ((number, number, number) => number)) => sampleSet ``` - -### correlation +### toList ``` -SampleSet.correlation: (sampleSet, sampleSet) => number +SampleSet.toList: (sampleSet) => list ``` - - - -### toInternalSampleArray -``` -SampleSet.toInternalSampleArray: (sampleSet) => list -``` -Gets the internal samples of a sampleSet distribution. This is separate from the sampleN() function, which would shuffle the samples. toInternalSampleArray() maintains order and length.Gets the internal samples of a sampleSet distribution. This is separate from the sampleN() function, which would shuffle the samples. toInternalSampleArray() maintains order and length. +Gets the internal samples of a sampleSet distribution. This is separate from the sampleN() function, which would shuffle the samples. toList() maintains order and length. Gets the internal samples of a sampleSet distribution. This is separate from the sampleN() function, which would shuffle the samples. toList() maintains order and length. **Examples** ``` -toInternalSampleArray(toSampleSet(normal(5,2))) +toList(toSampleSet(normal(5,2))) ``` \ No newline at end of file diff --git a/packages/website/docs/Api/Duration.md b/packages/website/docs/Api/Duration.md index a2af98d0..57df9d65 100644 --- a/packages/website/docs/Api/Duration.md +++ b/packages/website/docs/Api/Duration.md @@ -1,5 +1,5 @@ --- -sidebar_position: 5 +sidebar_position: 6 title: Duration --- @@ -8,86 +8,62 @@ title: Duration toString: (duration) => string ``` - - ### minutes ``` minutes: (number) => duration ``` - - ### hours ``` hours: (number) => duration ``` - - ### days ``` days: (number) => duration ``` - - ### years ``` years: (number) => duration ``` - - ### toHours ``` -Duration.toHours: (duration) => number +toHours: (duration) => number ``` - - ### toMinutes ``` -Duration.toMinutes: (duration) => number +toMinutes: (duration) => number ``` - - ### toDays ``` -Duration.toDays: (duration) => number +toDays: (duration) => number ``` - - ### toYears ``` -Duration.toYears: (duration) => number +toYears: (duration) => number ``` - - ### add ``` add: (duration, duration) => duration ``` - - ### subtract ``` subtract: (duration, duration) => duration ``` - - ### multiply ``` -multiply: (duration, duration) => duration +multiply: (duration, number) => duration ``` - - ### divide ``` -divide: (duration, duration) => duration -``` +divide: (duration, number) => duration +``` \ No newline at end of file diff --git a/packages/website/docs/Api/List.md b/packages/website/docs/Api/List.md index ef2e537e..06623b20 100644 --- a/packages/website/docs/Api/List.md +++ b/packages/website/docs/Api/List.md @@ -1,179 +1,81 @@ --- -sidebar_position: 6 +sidebar_position: 7 title: List --- -## make +### make ``` List.make: (number, 'a) => list<'a> -List.make: (number, number => a) => list<'a> -List.make: (pointSetDist) => list +``` +Returns an array of size ``n`` filled with value ``e``. + +```js +List.make(4, 1) // creates the list [1,1,1,1] ``` - +See [Rescript implementation](https://rescript-lang.org/docs/manual/latest/api/belt/array#make) ### toString ``` -List.toString: (list<'a>) => string +toString: (list<'a>) => string ``` - - ### length ``` -List.length: (list<'a>) => number +length: (list<'a>) => number ``` - - -### get +### up to ``` -List.get: (list<'a>, number) => 'a +List.upTo: (low:number, high:number) => list +``` +```js +List.upTo(0, 5) // creates the list [0,1,2,3,4,5] ``` - - -### find -``` -List.find: (list<'a>, 'a => bool) => 'a -``` - - - -### filter -``` -List.filter: (list<'a>, 'a => bool) => 'a -``` - - - -### set -``` -List.set: (list<'a>, number, 'a) => 'a -``` - - - -### shuffle -``` -List.shuffle: (list<'a>) => list<'a> -``` - - - -### reverse -``` -List.reverse: (list<'a>) => list<'a> -``` - - - -### range -``` -List.range: (low:number, high:number, increment?:number=1.0) => list -``` - - - -### zip -``` -List.zip: (list<'a>, list<'b>) => list> -``` - - - -### unzip -``` -List.unzip: (list>) => list, list<'b>> -``` - - - -### concat -``` -List.concat: (list<'a>, list<'b>) => list<'a|b> -``` - - - -### concatMany -``` -List.concatMany: (list>) => list<'a> -``` - - - -### slice -``` -List.slice: -``` - - - -### map -``` -List.map: (list<'a>, a => b) => list<'b> -``` - - - -### reduce -``` -List.reduce: -``` - - - -### reduceRight -``` -List.reduceRight: -``` - - - -### includes -``` -List.includes: (list<'a>, 'a => bool) => boolean -``` - - - -### every -``` -List.every: (list<'a>, 'a => bool) => boolean -``` - - - -### truncate -``` -List.truncate: (list<'a>, number) => list<'a> -``` - - - -### uniq -``` -List.uniq: (list<'a>) => list<'a> -``` - - +Syntax taken from [Ruby](https://apidock.com/ruby/v2_5_5/Integer/upto). ### first ``` -List.first: (list<'a>) => 'a +first: (list<'a>) => 'a ``` - - ### last ``` -List.last: (list<'a>) => 'a +last: (list<'a>) => 'a ``` - - -### sort +### reverse ``` -List.sort: (list<'a>) => list<'a> -``` \ No newline at end of file +reverse: (list<'a>) => list<'a> +``` + +### map +``` +map: (list<'a>, a => b) => list<'b> +``` + +See [Rescript implementation](https://rescript-lang.org/docs/manual/latest/api/belt/array#map). + +### reduce +``` +reduce: (list<'b>, 'a, ('a, 'b) => 'a) => 'a +``` +``reduce(arr, init, f)`` + +Applies ``f`` to each element of ``arr``. The function ``f`` has two paramaters, an accumulator and the next value from the array. + +```js +reduce([2, 3, 4], 1, {|acc, value| acc + value}) == 10 +``` + +See [Rescript implementation](https://rescript-lang.org/docs/manual/latest/api/belt/array#reduce). + +### reduce reverse +``` +reduceReverse: (list<'b>, 'a, ('a, 'b) => 'a) => 'a +``` + +Works like ``reduce``, but the function is applied to each item from the last back to the first. + +See [Rescript implementation](https://rescript-lang.org/docs/manual/latest/api/belt/array#reducereverse). \ No newline at end of file diff --git a/packages/website/docs/Api/Math.md b/packages/website/docs/Api/Math.md index fa8a65df..e64d6352 100644 --- a/packages/website/docs/Api/Math.md +++ b/packages/website/docs/Api/Math.md @@ -1,5 +1,5 @@ --- -sidebar_position: 7 +sidebar_position: 8 title: Math --- @@ -7,25 +7,19 @@ title: Math ``` Math.E: ``` -Euler's number; ≈ 2.718281828459045Euler's number; ≈ 2.718281828459045 - - +Euler's number; ≈ 2.718281828459045 ### LN2 ``` Math.LN2: ``` -Natural logarithm of 2; ≈ 0.6931471805599453Natural logarithm of 2; ≈ 0.6931471805599453 - - +Natural logarithm of 2; ≈ 0.6931471805599453 ### LN10 ``` Math.LN10: ``` -Natural logarithm of 10; ≈ 2.302585092994046Natural logarithm of 10; ≈ 2.302585092994046 - - +Natural logarithm of 10; ≈ 2.302585092994046 ### LOG2E ``` @@ -33,57 +27,38 @@ Math.LOG2E: ``` Base 2 logarithm of E; ≈ 1.4426950408889634Base 2 logarithm of E; ≈ 1.4426950408889634 - - ### LOG10E ``` Math.LOG10E: ``` -Base 10 logarithm of E; ≈ 0.4342944819032518Base 10 logarithm of E; ≈ 0.4342944819032518 - - +Base 10 logarithm of E; ≈ 0.4342944819032518 ### PI ``` Math.PI: ``` -Pi - ratio of the circumference to the diameter of a circle; ≈ 3.141592653589793Pi - ratio of the circumference to the diameter of a circle; ≈ 3.141592653589793 - - +Pi - ratio of the circumference to the diameter of a circle; ≈ 3.141592653589793 ### SQRT1_2 ``` Math.SQRT1_2: ``` -Square root of 1/2; ≈ 0.7071067811865476Square root of 1/2; ≈ 0.7071067811865476 - - +Square root of 1/2; ≈ 0.7071067811865476 ### SQRT2 ``` Math.SQRT2: ``` -Square root of 2; ≈ 1.4142135623730951Square root of 2; ≈ 1.4142135623730951 - - +Square root of 2; ≈ 1.4142135623730951 ### PHI ``` Math.PHI: ``` -Phi is the golden ratio. 1.618033988749895Phi is the golden ratio. 1.618033988749895 - - +Phi is the golden ratio. 1.618033988749895 ### TAU ``` Math.TAU: ``` -Tau is the ratio constant of a circle's circumference to radius, equal to 2 * pi. 6.283185307179586Tau is the ratio constant of a circle's circumference to radius, equal to 2 * pi. 6.283185307179586 - - - -### Infinity -``` -Math.Infinity: -``` \ No newline at end of file +Tau is the ratio constant of a circle's circumference to radius, equal to 2 * pi. 6.283185307179586 diff --git a/packages/website/docs/Api/Number.md b/packages/website/docs/Api/Number.md index ace6fd2f..dcd10752 100644 --- a/packages/website/docs/Api/Number.md +++ b/packages/website/docs/Api/Number.md @@ -1,166 +1,136 @@ --- -sidebar_position: 8 +sidebar_position: 9 title: Number --- ### ceil ```javascript -(number): number +ceil: (number) => number ``` ### floor ```javascript -(number): number +floor: (number) => number ``` ### abs ```javascript -(number): number +abs: (number) => number ``` ### round ```javascript -(number): number +round: (number) => number ``` ### max ```javascript -(list): number -``` - -### maxBy - -```javascript -(list, fn(element)):number +max: (list) => number ``` ### min ```javascript -(list): number -``` - -### minBy - -```javascript -(list, fn(element)):number -``` - -### random - -```javascript -number; -``` - -### randomInt - -```javascript -number; +min: (list) => number ``` ### mean ```javascript -(list): number +mean: (list) => number ``` -### median +### stdev ```javascript -(list): number -``` - -### mode - -```javascript -(list): number -``` - -### std - -```javascript -(list): number +stdev: (list) => number ``` ### variance ```javascript -(list): number +variance: (list) => number ``` ### unaryMinus ```javascript -(number): number +unaryMinus: (number) => number ``` ### equal ```javascript -(number, number): boolean +equal: (number, number) => boolean ``` ### add ```javascript -(number, number): number +add: (number, number) => number ``` ### sum ```javascript -(number, number): number +sum: (list) => number +``` + +### cumulative sum + +``` +cumsum: (list) => list ``` ### multiply ```javascript -(number, number): number +multiply: (number, number) => number ``` ### product ```javascript -(number, number): number +product: (list) => number +``` + +### cumulative product + +``` +cumprod: (list) => list ``` ### subtract ```javascript -(number, number): number +subtract: (number, number) => number ``` ### divide ```javascript -(number, number): number +divide: (number, number) => number ``` ### pow ```javascript -(number, number): number +pow: (number, number) => number ``` ### exp ```javascript -(number): number +exp: (number) => number ``` ### log ```javascript -(number, number=Math.e): number -``` - -### log10 - -```javascript -(number): number -``` +log: (number) => number +``` \ No newline at end of file