Chooses and executes a function for each variant in the Validation structure.
This API is still experimental, so it may change or be removed in future versions. You should not rely on it for production applications.
('a is Variant).({ 'b: (Object Any) => 'c }) => 'c
where 'b = 'a[`@@folktale:adt:tag]
Chooses and executes a function for each variant in the Validation structure.
const { Success, Failure } = require('folktale/validation');
Success('a').matchWith({
Failure: ({ value }) => `Failure: ${value}`,
Success: ({ value }) => `Success: ${value}`
});
// ==> 'Success: a'
Failure('a').matchWith({
Failure: ({ value }) => `Failure: ${value}`,
Success: ({ value }) => `Success: ${value}`
});
// ==> 'Failure: a'
matchWith(pattern) {
return pattern[name](this);
}