If the Result is a Ok, passes its value to the predicate. If the predicate returns true, then the Result is returned unchanged. In every other case, an Error gets returned.
This API is still experimental, so it may change or be removed in future versions. You should not rely on it for production applications.
forall a: (Maybe a).((a) => Boolean) => Maybe a
If the Result is a Ok, passes its value to the predicate. If the predicate returns true, then the Result is returned unchanged. In every other case, an Error gets returned.
const Result = require('folktale/result');
// This line evaluates to true.
Result.Ok.hasInstance(Result.Ok(3).filter(n => n === 3));
// These lines evaluate to false.
Result.Ok.hasInstance(Result.Ok(2).filter(n => n === 3));
Result.Ok.hasInstance(Result.Error(3).filter(n => n !== 3));
Result.Ok.hasInstance(Result.Error(3).filter(n => n === 3));
{
/*~*/
Error: function filter(predicate) {
assertFunction('Result.Error#filter', predicate);
return this;
},
/*~*/
Ok: function filter(predicate) {
assertFunction('Result.Ok#filter', predicate);
return predicate(this.value) ? this : Error();
}
}