Skip to content

Commit

Permalink
Document valid and less usual patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
bas080 committed Nov 23, 2021
1 parent aaf6763 commit b78f721
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.mz
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,35 @@ patroon([], 'is array')([])
patroon(Array, 'is array')([])
```

A less intuitive case:

```js ./tape-test > /dev/null
patroon({}, 'is object')([])
patroon([], 'is array')({})
```

Patroon allows this because Arrays can have properties defined.

```js ./tape-test > /dev/null
const array = []
array.prop = 42

patroon({prop: _}, 'has prop')(array)
```

The other way around is also allowed even if it seems weird.

```js ./tape-test > /dev/null
const object = {0: 'wow'}
patroon(['wow'], 'has 0th')(object)
```

If you do not desire this loose behavior you can use a predicate to make sure
something is an array or object.

```js ./tape-test > /dev/null
patroon(Array.isArray, 'is array')([])
```

### Reference

Expand Down

0 comments on commit b78f721

Please sign in to comment.