matchWith

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

This feature is experimental!

This API is still experimental, so it may change or be removed in future versions. You should not rely on it for production applications.

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 Result structure.

Example:

const Result = require('folktale/result');

Result.Ok(1).matchWith({
  Ok: ({ value }) => `ok ${value}`,
  Error: ({ value }) => `error ${value}`
});
// ==> 'ok 1'

Result.Error(1).matchWith({
  Ok: ({ value }) => `ok ${value}`,
  Error: ({ value }) => `error ${value}`
});
// ==> 'error 1'

Properties

Source Code

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