Combines two Results such that if they're both successful (Ok) their values are
concatenated. Otherwise returns the failure.
forall a, b: (Result a b).(Result a b) => Result a b
where b is SemigroupCombines two Results such that if they're both successful (Ok) their values are
concatenated. Otherwise returns the failure.
Note that values are expected to be Fantasy Land 1.x semigroups and implement a
concat method.
const Result = require('folktale/result');
Result.Ok([1]).concat(Result.Ok([2]));
// ==> Result.Ok([1, 2])
Result.Ok([1]).concat(Result.Error([2]));
// ==> Result.Error([2])
Result.Error([1]).concat(Result.Error([2]));
// ==> Result.Error([1])
Result.Error([1]).concat(Result.Ok([2]));
// ==> Result.Error([1])
{
/*~*/
Error: function concat(aResult) {
assertResult('Result.Error#concat', aResult);
return this;
},
/*~*/
Ok: function concat(aResult) {
assertResult('Result.Ok#concat', aResult);
return aResult.map(xs => this.value.concat(xs));
}
}