Skip to content
Eugene Lazutkin edited this page Jan 11, 2022 · 10 revisions

any is a special object, which matches any possible value. The same object is exported under a different alias: _ (underscore). See: _.

It is defined in env and exposed in the main module and unify as a convenience.

Introduction

import {any, match} from 'deep6';

match([1, 2, 3], [1, any, 3]); // true

match({a: 1, b: 2}, {a: any}); // true
match({a: 1, b: 2}, {b: any}); // true
match({a: 1, b: 2}, {c: any}); // false

const group = new Map();
group.set('bob', 'cool').set('mike', 'cool').set('ben', 'smart');

const pattern = new Map([['mike', any], ['bob', 'cool']]);

// do we have a mike and the cool bob in the group?
match(group, pattern);          // true

Notes

The current implementation:

const _ = Symbol.for('deep6.any'),
  any = _;
Clone this wiki locally