Skip to content

Commit adb77e5

Browse files
committed
Add FP framing to functions and void/never exercises
- Functions README: Introduce "transformations" and pure functions concept - Void/Never README: Reframe void as exception, emphasize side effects
1 parent b8dd189 commit adb77e5

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

exercises/04.functions/README.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ function add(a: number, b: number): number {
99
}
1010
```
1111

12+
<callout-info>
13+
Think of functions as **transformations**: data goes in, data comes out.
14+
Functions that always produce the same output for the same input (and don't
15+
change anything outside themselves) are called **pure functions**. They're the
16+
foundation of reliable, testable code.
17+
</callout-info>
18+
1219
## Anatomy of a TypeScript Function
1320

1421
```ts

exercises/05.void-and-never/README.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ Common side effects:
2222
- Sending analytics events
2323
- Writing to a database
2424

25+
<callout-info>
26+
Most functions should return a value (be "pure"). Functions with `void` return
27+
types are the exception—they exist to cause side effects. When you see `void`,
28+
you know the function is doing something beyond computing a result.
29+
</callout-info>
30+
2531
## The `never` Type
2632

2733
`never` means "this function never returns." It either:

0 commit comments

Comments
 (0)