Skip to content

Commit 3eccc3d

Browse files
authored
Merge pull request #1 from Indomitable/actions
Migrate to Typesript. Change name to fluent-iter.
2 parents 352cfce + a3fc029 commit 3eccc3d

163 files changed

Lines changed: 2344 additions & 2681 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.editorconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ end_of_line = lf
55
[{*.js,*.ts}]
66
indent_size = 4
77
indent_style = space
8-

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Use Bun
16+
uses: oven-sh/setup-bun@v1
17+
with:
18+
bun-version: latest
19+
- name: Install dependencies
20+
run: bun install
21+
- name: Test
22+
run: bun test

.gitignore

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
node_modules/
2-
coverage/
3-
.nyc_output/
4-
.idea
1+
node_modules/
2+
coverage/
3+
.nyc_output/
4+
.idea
5+

.travis.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

.zed/settings.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

README.md

Lines changed: 62 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
Modern-Linq
1+
Fluent-Iter
22
-------
3-
Modern-Linq is a library that brings the C# linq functionality into JavaScript. It is based on the native Iterable funtionality in JavaScript.
3+
Fluent-Iter is a library that allows you to work with iterables in a fluent way.
4+
It is full written in TypeScript and has no dependencies.
45

56
Examples:
67
```js
@@ -39,75 +40,69 @@ for (const item of query) {
3940
```
4041
Remarks:
4142

42-
1. The data is processed in the moment when is requested.
43+
1. The data is processed at the moment when is requested.
4344
2. The sequence is immutable the output !== input
4445

46+
Operators:
4547

46-
Some of the methods are using native Array implementation if the provided source is an Array
47-
Methods with native fallback:
48-
- `select`: uses Array.prototype.map
49-
- `where`: uses Array.prototype.filter
50-
- `take`: uses Array.prototype.slice
51-
- `skip`: uses Array.prototype.slice
52-
- `distinct`: if no comparer is provided it uses native Set class
53-
- `count`: returns Array.prototype.length
54-
- `orderBy`: Array.prototype.sort
55-
- `concat`: uses spread operator
48+
Transformers
49+
- where : filter iterable by predicate
50+
- select : transform iterable using mapping function
51+
- selectMany : flatten an iterable and can transform it to another iterable
52+
- ofType : produces typed iterable, used to filter by type
53+
- ofClass: filters iterable for elements of a given class
54+
- orderBy : Order iterable ascending by a key
55+
- orderByDescending : Order iterable descending by a key
56+
- groupJoin: Do a group join (left join) between current and external iterable. For each item of current sequence get array of items from external sequence.
57+
- join: Do an inner join between current and external sequence. For each item of current sequence get a item from external sequence.
58+
- page: Split iterable into chunks of a given size.
59+
- reverse: Reverse iterable.
5660

57-
Methods implemented:
58-
- `aggregate`
59-
- `any`
60-
- `all`
61-
- `concat`
62-
- `count`
63-
- `distinct`
64-
- `elementAt`
65-
- `first`
66-
- `firstOrDefault`
67-
- `groupJoin`
68-
- `join`
69-
- `intersect`
70-
- `last`
71-
- `lastOrDefault`
72-
- `max`
73-
- `min`
74-
- `ofType`
75-
- `orderBy`
76-
- `range`
77-
- `repeat`
78-
- `reverse`
79-
- `select`
80-
- `selectMany`
81-
- `isEqual` ( sequenceEqual )
82-
- `single`
83-
- `skip`
84-
- `skipLast`
85-
- `skipWhile`
86-
- `sum`
87-
- `take`
88-
- `takeLast`
89-
- `takeWhile`
90-
- `union`
91-
- `where`
61+
Slicing
62+
- take : take first n elements
63+
- takeWhile : take elements while predicate is true
64+
- takeLast : take last n elements
65+
- skip : skip first n elements
66+
- skipWhile : skip elements while predicate is true
67+
- skipLast : skip last n elements
9268

93-
- `toArray` ( toList )
94-
- `toMap` ( toDictionary )
95-
- `toSet`
69+
Combinations:
70+
- concat: Concat this iterable with another
71+
- distinct: removes duplicate elements
72+
- zip: zip two iterables together, where the result is an iterable of tuples, finishes when one of the iterables is finished.
73+
- union: Produce a union of two iterables where the result is distinct values from both.
74+
- intersect: Return an intersection of two iterables where the result is distinct values.
75+
- difference: Return elements from the first iterable that are not in the second. Only distinct values are returned.
76+
- except: Return elements from the first iterable that are not in the second. (TODO)
77+
- symmetricDifference: Return a symmetric difference ( distinct values except intersection ) of two iterables where the result is distinct values.
9678

97-
Waiting for implementation:
98-
- `contains`
99-
- `except`
100-
- `zip`
79+
Aggregators:
80+
- toArray(): convert iterable to array
81+
- toMap(): Create a map object from sequence
82+
- toSet(): Creates a set from current sequence
83+
- first : first element in iterable or first element that satisfies predicate
84+
- firstOrDefault: like first but with default value
85+
- firstOrThrows: like first but throws if no element is found
86+
- firstIndex: like first but returns index of element
87+
- last: last element in iterable or last element that satisfies predicate
88+
- lastOrDefault: like last but with default value
89+
- lastOrThrows: like last but throws if no element is found
90+
- lastIndex: like last but returns index of element
91+
- single: single element in iterable or single element that satisfies predicate. Throws if more than one element is found.
92+
- singleOrDefault: like single but with default value when nothing found. Throws if more than one element is found.
93+
- all: check if all elements in iterable satisfy predicate
94+
- allAndEvery: like all but requires to have at least one element
95+
- any: check if at least one element in iterable satisfies predicate
96+
- count: count elements in iterable or count of elements that satisfy predicate
97+
- aggregate: Produce single value form sequence values. The initial value is the second argument.
98+
- sum: Sum all elements in iterable
99+
- product: Multiply all elements in iterable
100+
- min: Get minimum value in iterable
101+
- max: Get maximum value in iterable
102+
- join: join all items from iterable with string concatenation
103+
- elementAt: get element at index
101104

102-
Extra methods
103-
- `isElementsEqual`: checks if two sequences have same elements, no matter of the position.
104-
- `product`: get the product of sequence.
105-
- `join` (with string argument): join all elements of sequence and concat with separator
106-
- `allAndEvery`: check a condition against all elements of sequence and sequence should not be empty.
107-
- `firstOrThrow`: returns first element if none throw error.
108-
- `lastOrThrow`: returns last element if none throw error.
109-
- `fistIndex`: return index of first element which is true for a predicate
110-
- `lastIndex`: return index of last element which is true for a predicate
111-
112-
Build status:
113-
[![Build Status](https://travis-ci.com/Indomitable/modern-linq.svg?branch=master)](https://travis-ci.com/Indomitable/modern-linq)
105+
Misc:
106+
- forEach: iterate over iterable and execute a function for each element
107+
- isEqual: check if two iterables are equal. Same elements and order.
108+
- isElementsEqual: check if two iterables are equal. Same elements but order can be different.

bun.lock

Lines changed: 3 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# dependencies (bun install)
2+
node_modules
3+
4+
# output
5+
out
6+
dist
7+
*.tgz
8+
9+
# code coverage
10+
coverage
11+
*.lcov
12+
13+
# logs
14+
logs
15+
_.log
16+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
17+
18+
# dotenv environment variable files
19+
.env
20+
.env.development.local
21+
.env.test.local
22+
.env.production.local
23+
.env.local
24+
25+
# caches
26+
.eslintcache
27+
.cache
28+
*.tsbuildinfo
29+
30+
# IntelliJ based IDEs
31+
.idea
32+
33+
# Finder (MacOS) folder config
34+
.DS_Store

example/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# example-fluent-iter
2+
3+
To install dependencies:
4+
5+
```bash
6+
bun install
7+
```
8+
9+
To run:
10+
11+
```bash
12+
bun run index.ts
13+
```
14+
15+
This project was created using `bun init` in bun v1.3.0. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.

example/bun.lock

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)