From d24869d0d2382f5aec6699f6bd78028fdee8ee1a Mon Sep 17 00:00:00 2001 From: Smoren Date: Thu, 20 Apr 2023 10:22:36 +0300 Subject: [PATCH] README and CHANGELOG updated. --- CHANGELOG.md | 13 ++++++++++++- README.md | 41 +++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f66279..39abc10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # IterTools Typescript Change Log +## v1.22.0 - 2023-04-20 + +### New features +* math + * `runningAverage()` + * `runningAverageAsync()` +* Stream + * `runningAverage()` +* AsyncStream + * `runningAverage()` + ## v1.21.0 - 2023-04-18 ### Improvements @@ -9,7 +20,7 @@ ## v1.20.0 - 2023-04-15 ### New features -* Math +* math * `runningDifference()` * `runningDifferenceAsync()` * `runningMax()` diff --git a/README.md b/README.md index b13e240..c138d56 100644 --- a/README.md +++ b/README.md @@ -141,6 +141,7 @@ Quick Reference #### Math Iteration | Iterator | Description | Sync Code Snippet | Async Code Snippet | |--------------------------------------------|---------------------------------|---------------------------------------------------|--------------------------------------------------------| +| [`runningAverage`](#Running-Average) | Running average accumulation | `math.runningAverage(numbers, [initialValue])` | `math.runningAverageAsync(numbers, [initialValue])` | | [`runningDifference`](#Running-Difference) | Running difference accumulation | `math.runningDifference(numbers, [initialValue])` | `math.runningDifferenceAsync(numbers, [initialValue])` | | [`runningMax`](#Running-Max) | Running maximum accumulation | `math.runningMax(numbers, [initialValue])` | `math.runningMax(numbers, [initialValue])` | | [`runningMin`](#Running-Min) | Running minimum accumulation | `math.runningMin(numbers, [initialValue])` | `math.runningMinAsync(numbers, [initialValue])` | @@ -226,6 +227,7 @@ Quick Reference | [`map`](#Map-1) | Map function onto elements | `stream.map(mapper)` | | [`pairwise`](#Pairwise-1) | Return pairs of elements from iterable source | `stream.pairwise()` | | [`partialIntersectionWith`](#Partial-Intersection-With) | Partially intersect stream and given iterables | `stream.partialIntersectionWith(minIntersectionCount, ...iterables)` | +| [`runningAverage`](#Running-Average-1) | Accumulate the running average (mean) over iterable source | `stream.runningAverage([initialValue])` | | [`runningDifference`](#Running-Difference-1) | Accumulate the running difference over iterable source | `stream.runningDifference([initialValue])` | | [`runningMax`](#Running-Max-1) | Accumulate the running max over iterable source | `stream.runningMax([initialValue])` | | [`runningMin`](#Running-Min-1) | Accumulate the running min over iterable source | `stream.runningMin([initialValue])` | @@ -887,6 +889,27 @@ for (const value of single.keys(dict)) { ## Math Iteration +### Running Average +Accumulate the running average over a list of numbers. + +``` +function* runningAverage( + numbers: Iterable | Iterator, + initialValue?: number +): Iterable +``` + +```typescript +import { math } from 'itertools-ts'; + +const grades = [100, 80, 80, 90, 85]; + +for (const runningAverage of math.runningAverage(grades)) { + console.log(runningAverage); +} +// 100, 90, 86.667, 87.5, 87 +``` + ### Running Difference Accumulate the running difference over a list of numbers. @@ -2365,6 +2388,24 @@ const result = Stream.of(staticallyTyped) // c++, java, c#, go, php ``` +#### Running Average +Return a stream accumulating the running average (mean) over the stream. + +``` +stream.runningAverage(initialValue?: number): Stream +``` + +```typescript +import { Stream } from 'itertools-ts'; + +const input = [1, 3, 5]; + +const result = Stream.of(input) + .runningAverage() + .toArray(); +// 1, 2, 3 +``` + #### Running Difference Return a stream accumulating the running difference over the stream. diff --git a/package.json b/package.json index 50b9baf..77f43c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "itertools-ts", - "version": "1.21.0", + "version": "1.22.0", "description": "Extended itertools port for TypeScript and JavaScript. Provides a huge set of functions for working with iterable collections (including async ones)", "license": "MIT", "repository": {