matchWith

Chooses and executes a function for each variant in the Maybe structure.

Signature

matchWith(pattern)
('a is Variant).({ 'b: (Object Any) => 'c }) => 'c
where 'b = 'a[`@@folktale:adt:tag]

Documentation

Chooses and executes a function for each variant in the Maybe structure.

Example:

const Maybe = require('folktale/maybe');

Maybe.Just(1).matchWith({
  Nothing: () => 'nothing',
  Just: ({ value }) => `got ${value}`
});
// ==> 'got 1'

Maybe.Nothing().matchWith({
  Nothing: () => 'nothing',
  Just: ({ value }) => `got ${value}`
});
// ==> 'nothing'

Properties

Source Code

Defined in source/adt/union/union.js at line 55, column 42
matchWith(pattern) {
        return pattern[name](this);
      }
Stability
stable
Licence
MIT
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • Quildreen Motta
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)