Skip to content

Commit 7be941d

Browse files
authored
Update APIDOC.md
1 parent aec10d4 commit 7be941d

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

APIDOC.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,45 @@ Download the [latest release](https://github.com/winterbe/sequency/releases) fro
77
```bash
88
npm install sequency
99
```
10+
or
11+
```bash
12+
yarn add sequency
13+
```
1014

11-
Or [try Sequency](https://npm.runkit.com/sequency) right in your browser.
15+
### How Sequency works
1216

13-
### How sequences works
17+
Sequency is centered around the interface [Sequence](https://winterbe.github.io/sequency/interfaces/Sequence.html) to process any kind of iterable data such as arrays, maps and sets.
1418

15-
Sequency is centered around a single class `Sequence` to process any kind of iterable data. The API is inspired by Kotlin [Sequences](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.sequences/-sequence/index.html).
19+
The interface `Sequence` provides a fluent functional API consisting of intermediate and terminal operations. Intermediate functions return a new sequence, thus enabling method chaining while terminal functions return an arbitrary result. You can explore all available `Sequence` operations by navigating to the [Sequence](https://winterbe.github.io/sequency/interfaces/Sequence.html) interface.
1620

17-
Each `Sequence` provides a fluent functional API consisting of intermediate and terminal operations. Intermediate functions return a new sequence, thus enabling method chaining while terminal functions return an arbitrary result. You can explore all available `Sequence` operations on this website by using the site navigation to the right.
21+
### Creating Sequences from your data
1822

1923
Sequences can be created with one of the following functions:
2024

2125
```js
22-
import {sequenceOf, asSequence, emptySequence} from 'sequency';
26+
import {sequenceOf, asSequence, emptySequence, generateSequence} from "sequency";
2327
```
2428

2529
- `sequenceOf` accepts one or many values and returns a new sequence.
2630
- `asSequence` accepts an iterable (e.g. an array, set or map) and returns a new sequence.
2731
- `emptySequence` returns a new empty sequence.
32+
- `generateSequence` creates a sequence from the results of the given generator function.
33+
34+
### Code sample
35+
36+
```js
37+
import {asSequence} from "sequency";
38+
39+
const numbers = [1, 2, 3, 4, 5];
2840

29-
Sequences are lazily evaluated to avoid examining all of the input data when it's not necessary. Sequences always perform the minimal amount of operations to gain results. E.g. in a `filter - map - find` sequence both `map` and `find` are executed just one time before returning the single result.
41+
const result = asSequence(numbers)
42+
.filter(num => num > 2)
43+
.reverse()
44+
.toArray()
45+
46+
// result: [5, 4, 3]
47+
```
3048

3149
### License
3250

33-
MIT © [Benjamin Winterberg](https://twitter.com/winterbe_)
51+
MIT © [winterbe](https://twitter.com/winterbe_)

0 commit comments

Comments
 (0)