You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+29-21Lines changed: 29 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,35 @@ A tiny utility function for composing asynchronous transformations
8
8
-[composable](#composition)
9
9
- works great with ES2017's `async/await`
10
10
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.
**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
+
consttransformFunctions= [
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
+
11
40
## Install
12
41
13
42
```
@@ -39,27 +68,6 @@ asyncTransform([transformFunctions], val); // added to window
39
68
</script>
40
69
```
41
70
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
-
consttransformFunctions= [
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
-
63
71
#### Partial application
64
72
65
73
You can also omit the `value` argument and `asyncTransform` will return a **transform function** that will return a promise:
0 commit comments