Skip to content

Commit c05743d

Browse files
committed
Update README
1 parent ea67bc5 commit c05743d

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,40 @@ Functional switch statement. Strictly typed.
1515
```js
1616
import switchFunctional from 'switch-functional'
1717

18+
const getUserType = (user) =>
19+
switchFunctional(user.type)
20+
.case('dev', 'developer')
21+
.case(['admin', 'owner'], 'administrator')
22+
.default('unknown')
23+
```
24+
25+
This is equivalent to:
26+
27+
<!-- eslint-disable no-restricted-syntax, no-fallthrough -->
28+
29+
```js
30+
const getUserType = (user) => {
31+
switch (user.type) {
32+
case 'dev': {
33+
return 'developer'
34+
}
35+
36+
case 'admin':
37+
38+
case 'owner': {
39+
return 'administrator'
40+
}
41+
42+
default: {
43+
return 'unknown'
44+
}
45+
}
46+
}
47+
```
48+
49+
## Testing input
50+
51+
```js
1852
const getUserType = (user) =>
1953
switchFunctional(user)
2054
.case(isDeveloper, 'developer')
@@ -50,7 +84,7 @@ const getUserType = (user) =>
5084
.default('unknown')
5185
```
5286

53-
## Dynamic return value
87+
## Returning dynamic values
5488

5589
<!-- eslint-disable no-shadow -->
5690

0 commit comments

Comments
 (0)