iterable-linq-utility 0.0.14 → 0.0.16
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.
- package/LICENSE +21 -21
- package/README.md +35 -1
- package/dist/{genericCollections → collections}/linkedList.d.ts +4 -2
- package/dist/functions/forEach.d.ts +1 -1
- package/dist/functions/index.d.ts +2 -2
- package/dist/functions/map.d.ts +1 -1
- package/dist/functions/max.d.ts +1 -1
- package/dist/functions/memoize.d.ts +5 -1
- package/dist/functions/min.d.ts +1 -1
- package/dist/functions/reduce.d.ts +1 -1
- package/dist/functions/some.d.ts +1 -1
- package/dist/functions/tap.d.ts +1 -1
- package/dist/functions/tapChain.d.ts +1 -1
- package/dist/interable-linq-utility.js +305 -214
- package/dist/interable-linq-utility.umd.cjs +1 -1
- package/dist/linqIterable.d.ts +4 -3
- package/dist/types/tapper.d.ts +2 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/validations.d.ts +5 -0
- package/package.json +59 -60
- package/dist/functions/_genericCollections.d.ts +0 -1
- package/dist/functions/_types.d.ts +0 -1
- package/dist/functions/_utils.d.ts +0 -1
- package/dist/genericCollections/_utils.d.ts +0 -1
- /package/dist/{genericCollections → collections}/index.d.ts +0 -0
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,35 @@
|
|
|
1
|
-
|
|
1
|
+
[](https://www.jsdelivr.com/package/npm/iterable-linq-utility)
|
|
2
|
+
|
|
3
|
+
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)).
|
|
4
|
+
|
|
5
|
+
[Official documentation available here](https://amebus.github.io/iterable-linq-utility)
|
|
6
|
+
|
|
7
|
+
## Main Idea
|
|
8
|
+
|
|
9
|
+
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].
|
|
10
|
+
In other words the idea is:
|
|
11
|
+
|
|
12
|
+
- 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)).
|
|
13
|
+
- 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:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
const myChain = IterableLinq.from([1,2,3,4]).filter().map(); // chain creation
|
|
17
|
+
const max = myChain.max();
|
|
18
|
+
const min = myChain.min(); // using the same chain twice
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
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.
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
IterableLinq
|
|
25
|
+
.fromRange(start, end)
|
|
26
|
+
.filter(myFilterFunction)
|
|
27
|
+
.map(myMapFunction)
|
|
28
|
+
.collectToArray()
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
as **Operations Chain** or **O~s~C**.
|
|
32
|
+
The **O~s~C** supports two types of operations:
|
|
33
|
+
|
|
34
|
+
- [Actions](https://amebus.github.io/iterable-linq-utility/api-reference/actions.md)
|
|
35
|
+
- [Transformations](https://amebus.github.io/iterable-linq-utility/api-reference/transformations.md)
|
|
@@ -3,7 +3,7 @@ export declare class LinkedList<T> implements Iterable<T> {
|
|
|
3
3
|
private internalSize;
|
|
4
4
|
private head;
|
|
5
5
|
private tail;
|
|
6
|
-
[Symbol.iterator]():
|
|
6
|
+
[Symbol.iterator](): LinkedListIterator<T>;
|
|
7
7
|
private internalAddFirst;
|
|
8
8
|
addFirst(value: T): this;
|
|
9
9
|
private internalAddLast;
|
|
@@ -12,8 +12,10 @@ export declare class LinkedList<T> implements Iterable<T> {
|
|
|
12
12
|
}
|
|
13
13
|
export declare class LinkedListIterator<T> implements Iterator<T> {
|
|
14
14
|
private current;
|
|
15
|
-
constructor(current
|
|
15
|
+
constructor(current: IListNode<T> | null);
|
|
16
|
+
private innerNext;
|
|
16
17
|
next(): IteratorResult<T, any>;
|
|
18
|
+
return(value?: any): IteratorResult<T, any>;
|
|
17
19
|
}
|
|
18
20
|
interface IListNode<T> {
|
|
19
21
|
data: T;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Action, AsyncAction, Unit } from "
|
|
1
|
+
import { Action, AsyncAction, Unit } from "../types";
|
|
2
2
|
export declare function forEach<T>(iterable: Iterable<T>, action: Action<T>): Unit;
|
|
3
3
|
export declare function forEachAsync<T>(iterable: Iterable<T>, action: AsyncAction<T>): Promise<Unit>;
|
|
@@ -9,9 +9,9 @@ export { filter, flatMap, forEach, forEachAsync };
|
|
|
9
9
|
import { map } from './map';
|
|
10
10
|
import { materialize } from './materialize';
|
|
11
11
|
import { max } from './max';
|
|
12
|
-
import { memoize } from './memoize';
|
|
12
|
+
import { memoize, getMemoizeDefaultOptions, IMemoizeOptions } from './memoize';
|
|
13
13
|
import { min } from './min';
|
|
14
|
-
export { map, materialize, max, memoize, min };
|
|
14
|
+
export { map, materialize, max, memoize, getMemoizeDefaultOptions, type IMemoizeOptions, min };
|
|
15
15
|
import { range } from './range';
|
|
16
16
|
import { reduce } from './reduce';
|
|
17
17
|
import { repeat } from './repeat';
|
package/dist/functions/map.d.ts
CHANGED
package/dist/functions/max.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
export interface IMemoizeOptions {
|
|
2
|
+
allowPartialMemoization?: boolean;
|
|
3
|
+
}
|
|
4
|
+
export declare function getMemoizeDefaultOptions(): IMemoizeOptions;
|
|
1
5
|
/**
|
|
2
6
|
*
|
|
3
7
|
* @operation `Transformation`
|
|
4
8
|
* @param iterable
|
|
5
9
|
* @returns
|
|
6
10
|
*/
|
|
7
|
-
export declare function memoize<T>(iterable: Iterable<T
|
|
11
|
+
export declare function memoize<T>(iterable: Iterable<T>, options?: IMemoizeOptions): Iterable<T>;
|
package/dist/functions/min.d.ts
CHANGED
package/dist/functions/some.d.ts
CHANGED
package/dist/functions/tap.d.ts
CHANGED