concat

Combines two Results such that if they're both successful (Ok) their values are concatenated. Otherwise returns the failure.

Signature

forall a, b: (Result a b).(Result a b) => Result a b
where b is Semigroup

Documentation

Combines 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.

Example:

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])

Properties

Source Code

Defined in source/result/result.js at line 75, column 19
{
    /*~*/
    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));
    }
  }
Stability
stable
Licence
MIT
Module
folktale/result/result
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • Quildreen Motta
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)