Skip to content

Commit 1b4481f

Browse files
authored
Merge pull request #1 from dbrack/improvements
Fix typos and grammar improvements
2 parents f3f8336 + c6275c2 commit 1b4481f

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Resulting code will have improved maintainability and better runtime type safety
88

99
Pattern matching is a fundamental and powerful building block to many functional programming languages like [Haskell](http://learnyouahaskell.com/syntax-in-functions) or [Scala](http://docs.scala-lang.org/tutorials/tour/pattern-matching.html).
1010

11-
*TODO: Disclaimer: Language-Level Pattern matchers go further than what we build here… Though its a nice abstraction pattern to improve code maintainability*
11+
*TODO: Disclaimer: Language-Level Pattern matchers go further than what we build here… Though it's a nice abstraction pattern to improve code maintainability*
1212

13-
A *pattern* can contain one or more *cases*. Each *case* describes *behaviour* which has to be applied once the *case* matches.
13+
A *pattern* can contain one or more *cases*. Each *case* describes *behavior* which has to be applied once the *case* matches.
1414

1515
You might think: *"Hey! That sounds like a `switch` statement to me!"*. And you are right indeed:
1616

@@ -39,21 +39,21 @@ console.log(matchNumber(randomNumber()));
3939

4040
We can use a `switch` statement to map `number`s to its desired `string` representation.
4141

42-
Doing so is straight forward, though we can make out flaws for `matchNumber`:
42+
Doing so is straightforward, though we can make out flaws for `matchNumber`:
4343

44-
1. The *behaviour* for each case is baked into the `matchNumber` function. If you want to map `number`s to, lets say `boolean`s, you have to reimplement the complete `switch` block in another function.
45-
2. Requirements can be misinterpreted and behaviour for a case gets lost. What about `4`? What if a developer forgets about `default`?
44+
1. The *behavior* for each case is baked into the `matchNumber` function. If you want to map `number`s too, let's say `boolean`s, you have to reimplement the complete `switch` block in another function.
45+
2. Requirements can be misinterpreted and behavior for a case gets lost. What about `4`? What if a developer forgets about `default`?
4646
The possibility of bugs multiplies easily when the `switch` is reimplemented several times as described under point 1.
4747

4848
Trying to solve these flaws outlines requirements for an improved solution:
4949

50-
1. Separate matching a specific *case* from its *behaviour*
50+
1. Separate matching a specific *case* from its *behavior*
5151
2. Make reuse of matcher simple to prevent bugs through duplicated code
5252
3. Implement matcher once for different types
5353

5454
## Separation of Concerns
5555

56-
Lets define an interface containing functions for each *case* we want be able to match. This allows to separate behaviour from actual matcher logic later.
56+
Let's define an interface containing functions for each *case* we want to be able to match. This allows separating behavior from actual matcher logic later.
5757

5858
```typescript
5959
interface NumberPattern {
@@ -98,7 +98,7 @@ const match = matchNumber({
9898
console.log(match(randomNumber()))
9999
```
100100

101-
We clearly separated *case behaviours* from the matcher. That first point can be ticked off. Does it further us from duplicating code and improve maintainability of the matcher?
101+
We clearly separated *case behaviors* from the matcher. That first point can be ticked off. Does it further duplicating code and improve maintainability of the matcher?
102102

103103
```typescript
104104
const matchGerman = matchNumber({
@@ -111,7 +111,7 @@ const matchGerman = matchNumber({
111111
console.log(matchGerman(randomNumber()))
112112
```
113113

114-
Another tick! Because we have split concerns by introducing `NumberPattern`, changing behavior without reimplementing the underlying matcher logic is straight forward.
114+
Another tick! Because we have split concerns by introducing `NumberPattern`, changing behavior without reimplementing the underlying matcher logic is straightforward.
115115

116116
## Truly Reusable
117117

@@ -143,7 +143,9 @@ const isLargerThanThree = matchNumber({
143143
});
144144

145145
console.log(isLargerThanThree(100));
146+
// results in true
146147
console.log(isLargerThanThree(1));
148+
// results in false
147149
```
148150

149151
This fulfills the last point in our requirement list to implement the matcher once for different types. The final example will probably never make it to production code, though it demonstrates the basic mechanic how a pattern and a corresponding matcher can be implemented in TypeScript.

0 commit comments

Comments
 (0)