diff --git a/README.md b/README.md index 4415648..21b4bd8 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,9 @@ npm install sums-up ``` -### Example: +### Example + +In TypeScript: ```typescript import SumType from 'sums-up'; @@ -30,6 +32,29 @@ const result = x.caseOf({ }); ``` +Or in JavaScript + +```javascript +import SumType from 'sums-up'; + +class Maybe extends SumType {} + +function Just(value) { + return new Maybe("Just", value); +} + +function Nothing() { + return new Maybe("Nothing"); +} + +const x = Just("foo"); + +const result = x.caseOf({ + Nothing: () => "nope", + Just: (a) => a + "bar", +}); +``` + ### Wildcard Matching If the kind of a sum type instance isn't present in the pattern given to `caseOf`, a default key called `_` will be used instead.