Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including match-toy with all npm packages installed. Try it out:

const { match } = require('match-toy'); const factorial = match .case('0', () => 1) .case('n', ({ n }) => n * factorial(n - 1)) .end(); console.log('0', factorial(0)); console.log('4', factorial(4)); console.log('10', factorial(10)); const howMany = match .case('[]', () => 'empty') .case('[_]', () => 'one') .case('[_, _]', () => 'two') .case('[_, _, ...]', () => 'more than two') .else(() => 'it is not a list') .end(); console.log(howMany([])); console.log(howMany([1])); console.log(howMany([1, 2])); console.log(howMany([1, 2, 3])); console.log(howMany('?'));

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

match-toy v3.0.3

The pattern matching library for javascript

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free