Skip to content

Commit 918eece

Browse files
authored
Tweak 04_goingfunctional for fluency
1 parent 1bae6af commit 918eece

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

packages/overmind-website/guides/intermediate/04_goingfunctional.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Going functional
22

3-
You get very far building your application with straight forward imperative actions. This is typically how we learn programming and is arguably close to how we think about the world. But this approach can cause you to overload your actions with imperative code, making them more difficult to read and especially reuse pieces of logic. As the complexity of your application increases you will find benefits doing some of your logic, or maybe all your logic, in a functional style.
3+
You get very far building your application with straightforward imperative actions. This is typically how we learn programming and is arguably close to how we think about the world. But this approach can cause you to overload your actions with imperative code, making them more difficult to read and especially reuse pieces of logic. As the complexity of your application increases you will find benefits to doing some of your logic, or maybe all your logic, in a functional style.
44

55
Let us look at a concrete example of how messy an imperative approach would be compared to a functional approach.
66

77
```marksy
88
h(Example, { name: "guide/goingfunctional/messy" })
99
```
1010

11-
What we see here is an action trying to express a search. We only want to search when the length of the query is more than 2 and we only want to trigger the search when the user has not changed the query for 200 milliseconds.
11+
What we see here is an action trying to express a search. We only want to search when the length of the query is more than 2 characters and we only want to trigger the search when the user has not changed the query for 200 milliseconds.
1212

1313
If we were to do this in a functional style it would look more like this:
1414

@@ -37,8 +37,8 @@ h(Notice, null, "Note that we give all the actual operator functions the same na
3737

3838
You might wonder why we define the operators as functions that we call. We do that for the following reasons:
3939

40-
1. It ensures that each composition using the operator has a unique instance of that operator. For most operators this does not matter, but for others like **debounce** it actually matters
41-
2. Some operators requires options, like the **lengthGreaterThan** operator we created above. Defining all operators as functions just makes things more consistent
40+
1. It ensures that each composition using the operator has a unique instance of that operator. For most operators this does not matter, but for others like **debounce** it actually matters.
41+
2. Some operators require options, like the **lengthGreaterThan** operator we created above. Defining all operators as functions just makes things more consistent.
4242
3. If you were to create an operator that is composed of other operators you can safely do so without thinking about the order of definition in the *operators* file. The reason being that the operator is lazily created
4343

4444
```marksy
@@ -71,4 +71,4 @@ h(Example, { name: "guide/goingfunctional/map" })
7171

7272
```marksy
7373
h(TypescriptNotice, null, "Notice here that we are typing both the input and the output. Both for the **map** operator and the **pipe** operator. This is important to manage the composition of operators. Typically operators pass on the same value they receive, meaning that you do not need the second typing parameter for the **Operator** type.")
74-
```
74+
```

0 commit comments

Comments
 (0)