Skip to content

Commit 8e6e725

Browse files
committed
Better explain step
1 parent 4875b0f commit 8e6e725

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Generators make testing difficult in that:
1616

1717
- They can have internal state.
1818
- Each segment of the function cannot be tested in isolation.
19-
- Each segment of the function can only be reach after the segments before it.
20-
- Generators are awkward. Conversing with a generator with `next()` isn't as simple as function calling.
19+
- Each segment of the function can only be reached after the segments before it.
20+
- Generators are awkward. Conversing with a generator using `next()` isn't as simple as function calling.
2121
- Composition of generators is harder than functions inherently.
2222

2323
So Affection is all about functions, with the goals:
@@ -153,11 +153,25 @@ A step is a means of encapsulating an effect without needing a plan (as describe
153153

154154
This is hard to understand without an understanding of how `run` works.
155155
The `run` function is recursively executing plans until there is nothing more to do.
156-
A step is a way of saying, "Execute this effect; we might be done, might not."
157-
There could be 5 more effects to run or it's the end result; the step doesn't need to know.
158-
156+
A step is a way of saying, "Execute this effect; I don't know what happens with the result."
159157
This is for code reuse: effects should be decoupled from their consumers.
160158

159+
For more clarity, let's look at the `step` function:
160+
161+
```js
162+
const step = makeEffect => next => input => [makeEffect(input), next]
163+
```
164+
165+
We define our `makeEffect` without needing to know the consumer.
166+
The `next` is what will consume the result.
167+
Later, steps are composed when the consumers are known.
168+
Finally, the step is given an `input` to build its effect.
169+
170+
In summary, steps decouple:
171+
- Creating the effect: `makeEffect`
172+
- Consuming the effect's result: `next`
173+
- Building the final plan, given an `input`
174+
161175
### `mapStep`
162176
> `mapStep(step: Step, transform: function): Step`
163177

0 commit comments

Comments
 (0)