Skip to content

Commit

Permalink
Update Basic Usage on README
Browse files Browse the repository at this point in the history
  • Loading branch information
namikingsoft committed Nov 11, 2015
1 parent 9581179 commit 5d90d97
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ In case of ECMAScript6
```javascript
import match from 'match-case'

// two function args
const result1 = match(10).
caseOf(n => n > 0, v => v * v).
caseOf(n => n < 0, v => v + v).
caseOfElse(404).
end()

assert(result1 === 100)

// one object arg with function
const result2 = match(-1).
caseOf({
when: n => n > 0,
Expand All @@ -43,17 +46,17 @@ get()

assert(result2 === 404)

import match from 'match-case'

// equal value
const result3 = match(2).
caseOf(1, 10).
caseOf(2, 20).
caseOf(2, 30).
caseOf(n => n > 0, 30).
caseOfElse(404).
end()

assert(result3 === 20)
assert(result3 === 20) // first match case

// match after case construction
const matcher = match().
caseOf(n => n > 0, 200).
caseOfNone(404).
Expand Down

0 comments on commit 5d90d97

Please sign in to comment.