concat

Combines two maybes such that if they both have values (are a Just) their values are concatenated. Maybe values are expected to be Fantasy Land 1.x semigroups and implement a concat method.

Signature

forall a: (Maybe a).(Maybe a) => Maybe a
where a is Semigroup

Documentation

Combines two maybes such that if they both have values (are a Just) their values are concatenated. Maybe values are expected to be Fantasy Land 1.x semigroups and implement a concat method.

Example:

const Maybe = require('folktale/maybe');

Maybe.Just([1]).concat(Maybe.Just([2]));
// ==> Maybe.Just([1, 2])

Maybe.Just([1]).concat(Maybe.Nothing());
// ==> Maybe.Just([1])

Maybe.Nothing().concat(Maybe.Nothing());
// ==> Maybe.Nothing()

Properties

Source Code

Defined in source/maybe/maybe.js at line 57, column 18
{
    /*~*/
    Nothing: function concat(aMaybe) {
      assertMaybe('Maybe.Nothing#concat', aMaybe);
      return aMaybe;
    },

    /*~*/
    Just: function concat(aMaybe) {
      assertMaybe('Maybe.Just#concat', aMaybe);
      return aMaybe.matchWith({
        Nothing: () => Just(this.value),
        Just: (a) => Just(this.value.concat(a.value))
      });
    }
  }
Licence
MIT
Module
folktale/maybe/maybe
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • @diasbruno
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)