Skip to content

Commit 349006b

Browse files
authored
Update README.md
Add signature to README and move example and explanation up
1 parent 8ec69f5 commit 349006b

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

README.md

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,35 @@ A tiny utility function for composing asynchronous transformations
88
- [composable](#composition)
99
- works great with ES2017's `async/await`
1010

11+
**Async-Transform** is a simple function, that takes an array of **transform functions** and a **value** and runs each transform function in sequence, passing along the result of the last transform function and **returns a promise**.
12+
13+
There is also an option to create **async tranform functions** by using [partial application](#partial-application), which makes composition trivial.
14+
15+
##### `asyncTransform(transformFunctions:array(Function)[, value:any, context:any]) -> Promise(any)`
16+
17+
**Transform Functions** are just functions that follow this pattern:
18+
19+
- They accept 1 argument (the value)
20+
- they return either a value or a promise that resolves to a value
21+
- they **do not** return `undefined` as the value, and should guard against so
22+
23+
That's it.
24+
25+
#### Basic use
26+
27+
```javascript
28+
// some are sync transforms, some are async
29+
const transformFunctions = [
30+
v => v+1,
31+
v => Promise.resolve(v*2),
32+
v => v*v,
33+
v => Promise.resolve({foo:v})
34+
];
35+
36+
asyncTransform(funcs, 1)
37+
.then( v => console.log(v) ); // { foo: 16 }
38+
```
39+
1140
## Install
1241

1342
```
@@ -39,27 +68,6 @@ asyncTransform([transformFunctions], val); // added to window
3968
</script>
4069
```
4170

42-
## Use
43-
44-
Async-Transform is a simple utility function, that takes an array of **transform functions** and a **value** and runs each transform function in sequence, passing the result of the last transform function (or value at the start) as the sole argument. `asyncTransform` returns a promise, which makes chaining and composing transform functions trivial.
45-
46-
A **transform function** is just a function that takes a single argument as the value and returns either a new value, or a promise that will resolve to a new value.
47-
48-
#### Basic use
49-
50-
```javascript
51-
// some are sync transforms, some are async
52-
const transformFunctions = [
53-
v => v+1,
54-
v => Promise.resolve(v*2),
55-
v => v*v,
56-
v => Promise.resolve({foo:v})
57-
];
58-
59-
asyncTransform(funcs, 1)
60-
.then( v => console.log(v) ); // { foo: 16 }
61-
```
62-
6371
#### Partial application
6472

6573
You can also omit the `value` argument and `asyncTransform` will return a **transform function** that will return a promise:

0 commit comments

Comments
 (0)