-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: caseof can pattern match strings and numbers
- Loading branch information
Showing
7 changed files
with
66 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as test from "tape"; | ||
import caseOf from "./"; | ||
|
||
import Either from "../../adt/Either"; | ||
|
||
test("caseOf", t => { | ||
const e1 = Either.of(1); | ||
t.equals( | ||
caseOf({ Right: v => v + 1, Left: x => x }, e1), | ||
2, | ||
"pattern match" | ||
); | ||
t.throws( | ||
() => caseOf({ Right: v => v + 1, Left: x => x }, "hello"), | ||
"pattern match fail" | ||
); | ||
t.equals( | ||
caseOf({ string: x => x, _: x => x }, "string"), | ||
"string", | ||
"pattern match strings" | ||
); | ||
t.equals( | ||
caseOf({ string: x => x, _: x => x }, 1), | ||
1, | ||
"pattern match numbers" | ||
); | ||
t.throws( | ||
() => caseOf({ str: x => x }, "hello"), | ||
"Must provide default case for strings" | ||
); | ||
t.throws( | ||
() => caseOf({ 5: x => x }, 1), | ||
"Must provide default case for numbers" | ||
); | ||
t.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters