swap

Inverts the context of a Result value such that Errors are transformed into Oks, and Oks are transformed into Errors. Does not touch the value inside of the Result.

This feature is experimental!

This API is still experimental, so it may change or be removed in future versions. You should not rely on it for production applications.

Signature

forall a, b: (Result a b).() => Result b a

Documentation

Inverts the context of a Result value such that Errors are transformed into Oks, and Oks are transformed into Errors. Does not touch the value inside of the Result.

Example:

const Result = require('folktale/result');

Result.Ok(1).swap();
// ==> Result.Error(1)

Result.Error(1).swap();
// ==> Result.Ok(1)

Properties

Source Code

Defined in source/result/result.js at line 75, column 19
{
    /*~*/
    Error: function swap() {
      return Ok(this.value);
    },

    /*~*/
    Ok: function swap() {
      return Error(this.value);
    }
  }
Stability
experimental
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/)