iterable-linq-utility 0.0.15 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +107 -1
  3. package/dist/index.d.cts +847 -0
  4. package/dist/index.d.ts +847 -14
  5. package/dist/iterable-linq-utility.js +632 -0
  6. package/dist/iterable-linq-utility.umd.cjs +1 -0
  7. package/package.json +70 -60
  8. package/dist/functions/_genericCollections.d.ts +0 -1
  9. package/dist/functions/_types.d.ts +0 -1
  10. package/dist/functions/_utils.d.ts +0 -1
  11. package/dist/functions/collectToArray.d.ts +0 -1
  12. package/dist/functions/empty.d.ts +0 -1
  13. package/dist/functions/filter.d.ts +0 -9
  14. package/dist/functions/flatMap.d.ts +0 -8
  15. package/dist/functions/forEach.d.ts +0 -3
  16. package/dist/functions/index.d.ts +0 -23
  17. package/dist/functions/map.d.ts +0 -9
  18. package/dist/functions/materialize.d.ts +0 -7
  19. package/dist/functions/max.d.ts +0 -9
  20. package/dist/functions/memoize.d.ts +0 -7
  21. package/dist/functions/min.d.ts +0 -9
  22. package/dist/functions/range.d.ts +0 -7
  23. package/dist/functions/reduce.d.ts +0 -10
  24. package/dist/functions/repeat.d.ts +0 -1
  25. package/dist/functions/some.d.ts +0 -9
  26. package/dist/functions/tap.d.ts +0 -9
  27. package/dist/functions/tapChain.d.ts +0 -9
  28. package/dist/genericCollections/_utils.d.ts +0 -1
  29. package/dist/genericCollections/index.d.ts +0 -2
  30. package/dist/genericCollections/linkedList.d.ts +0 -22
  31. package/dist/interable-linq-utility.js +0 -617
  32. package/dist/interable-linq-utility.umd.cjs +0 -1
  33. package/dist/linqIterable.d.ts +0 -44
  34. package/dist/types/action.d.ts +0 -3
  35. package/dist/types/comparer.d.ts +0 -4
  36. package/dist/types/index.d.ts +0 -7
  37. package/dist/types/mapper.d.ts +0 -1
  38. package/dist/types/predicate.d.ts +0 -1
  39. package/dist/types/reducer.d.ts +0 -1
  40. package/dist/types/tapper.d.ts +0 -1
  41. package/dist/types/unit.d.ts +0 -3
  42. package/dist/utils/index.d.ts +0 -2
  43. package/dist/utils/iteratorResults.d.ts +0 -4
  44. package/dist/utils/utils.d.ts +0 -56
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) [2022] [Federico Maria Ceruti]
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) [2022] [Federico Maria Ceruti]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1 +1,107 @@
1
- Work in Progress
1
+ [![](https://data.jsdelivr.com/v1/package/npm/iterable-linq-utility/badge)](https://www.jsdelivr.com/package/npm/iterable-linq-utility)
2
+ [![](https://img.shields.io/npm/v/iterable-linq-utility.svg)](https://npmjs.org/package/iterable-linq-utility)
3
+ [![](https://img.shields.io/npm/dm/iterable-linq-utility.svg)](https://npmjs.org/package/iterable-linq-utility)
4
+
5
+ A [.NET Linq to Objects](https://learn.microsoft.com/it-it/dotnet/csharp/programming-guide/concepts/linq/linq-to-objects) porting with javacript naming conventions (e.g.: `Select` as been ranamed to `map`) and some new features (e.g.: [memoize](https://amebus.github.io/iterable-linq-utility/api-reference/transformations.md#memoize) and [materialize](https://amebus.github.io/iterable-linq-utility/api-reference/actions.md#materialize)).
6
+
7
+ [Official documentation available here](https://amebus.github.io/iterable-linq-utility)
8
+
9
+ ## Main Idea
10
+
11
+ As the previous description says, the idea is to create a kind-of-porting of [.NET Linq to Objects](https://learn.microsoft.com/it-it/dotnet/csharp/programming-guide/concepts/linq/linq-to-objects) with a naming convetions that is more javascript and functional programming oriented and not sql oriented [^1].
12
+ In other words the idea is:
13
+
14
+ - to keep the [LINQ Deferred Exceution](https://learn.microsoft.com/en-us/dotnet/standard/linq/deferred-execution-lazy-evaluation#deferred-execution) and apply it to the [JavaScript Iterator Protocol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) with a more standard way of naming well known high order functions like `map`, `flatMap`, `reduce` used by javascript and some functional programming libraries (e.g.: [Ramdajs](https://github.com/functionalland/ramda), [SanctuaryJs](https://github.com/orgs/sanctuary-js/repositories?type=all), [FantasyLand](https://github.com/fantasyland) and [lodash](https://github.com/lodash/lodash)).
15
+ - to keep the **Linq repeatable execution** which allows to traverse the same chain multiple times without having to recreate it from scratch every time, in this way is possible to store the chain in a variable and then trigger it to get the max and min without recreating it:
16
+
17
+ ```ts
18
+ const myChain = IterableLinq.from([1,2,3,4]).filter().map(); // chain creation
19
+ const max = myChain.max();
20
+ const min = myChain.min(); // using the same chain twice
21
+ ```
22
+
23
+ Since in javascript you cannot rely on [extensions methods](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/extension-methods) as in c# there is the need to create a wrapper over `Iterable` to achive the same [Deferred Exceution](https://learn.microsoft.com/en-us/dotnet/standard/linq/deferred-execution-lazy-evaluation#deferred-execution) concept.
24
+
25
+ ```typescript
26
+ IterableLinq
27
+ .fromRange(start, end)
28
+ .filter(myFilterFunction)
29
+ .map(myMapFunction)
30
+ .collectToArray()
31
+ ```
32
+
33
+ as **Operations Chain** or **O~s~C**.
34
+ The **O~s~C** supports two types of operations:
35
+
36
+ - [Actions](https://amebus.github.io/iterable-linq-utility/api-reference/actions.md)
37
+ - [Transformations](https://amebus.github.io/iterable-linq-utility/api-reference/transformations.md)
38
+
39
+ ## Benchmarks
40
+
41
+ The benchmarks use [Vitest benchmarking](https://vitest.dev/guide/benchmarking) and live in `test/bench`:
42
+
43
+ - `functions/`: one file for each function, with several variants (for example `min` with no comparer, a compare function, a key and a list of keys);
44
+ - `chains/`: whole chains, from `map(filter(range))` to multi-stage pipelines, early exits and chains read by more than one action.
45
+
46
+ Every table compares the library with a native reference (an array method or a hand-written loop) and, where it exists, with the raw function in `Functions`.
47
+
48
+ The benchmarks measure the built bundle (`dist/iterable-linq-utility.js`), the same code that users run. The `bench` scripts build it first.
49
+
50
+ ### Run
51
+
52
+ ```sh
53
+ pnpm bench # every benchmark, about 3 minutes
54
+ pnpm bench functions/min # only the files whose path contains "functions/min"
55
+ pnpm bench chains # only the chains
56
+ BENCH_TIME=1000 pnpm bench # more time for each case (default 500 ms): more samples, less noise
57
+ ```
58
+
59
+ ### Find regressions
60
+
61
+ A baseline is a saved run. Each table shows it as extra rows, marked `(baseline)`, next to the new run.
62
+
63
+ ```sh
64
+ git switch main
65
+ pnpm bench:baseline # saves every result in .bench/
66
+ git switch my-branch
67
+ pnpm bench # shows each case next to its "(baseline)" row
68
+ ```
69
+
70
+ The timings depend on the machine, so `.bench/` is not committed and the benchmarks do not run in CI. Create the baseline and the new run on the same machine, with the same load.
71
+
72
+ ### Read the tables
73
+
74
+ | Column | Meaning |
75
+ |---|---|
76
+ | `hz` | runs per second: higher is faster |
77
+ | `mean`, `p75`, `p99` | time of one run, in ms |
78
+ | `rme` | relative margin of error |
79
+ | `samples` | how many runs were measured |
80
+
81
+ A difference smaller than the `rme` of the two rows is noise.
82
+
83
+ ### Add a benchmark
84
+
85
+ Create `test/bench/functions/<name>.bench.ts` or `test/bench/chains/<scenario>.bench.ts`:
86
+
87
+ ```ts
88
+ import * as IterableLinq from 'iterable-linq-utility';
89
+ import { test } from 'vitest';
90
+
91
+ import * as Helpers from '../helpers';
92
+
93
+ // Read the exports once: an imported binding goes through a module runner getter on every read.
94
+ const { from } = IterableLinq;
95
+ const { cases, numbers, sum } = Helpers;
96
+
97
+ test('map: number', async ({ bench }) => {
98
+ await cases(bench, 'map/number') // the baseline folder: <function>/<variant>
99
+ .add('native', () => sum(numbers.map(v => v * 2)))
100
+ .add('chain', () => sum(from(numbers).map(v => v * 2)))
101
+ .run();
102
+ });
103
+ ```
104
+
105
+ - Every table needs at least two cases: add a native reference.
106
+ - Import the library and the helpers as namespaces and copy the exports into local constants, as above. Vitest prints a `Benchmark Warning` when a benchmark reads an imported binding too many times.
107
+ - The shared data is in `test/bench/helpers.ts`: `numbers` (100,000 integers), `records` (100,000 objects) and `small` (1,000 integers).