fromNullable

A convenience method for the folktale/conversions/nullable-to-result module.

Signature

fromNullable(aNullable, fallbackValue)
forall a, b: (a or None, b) => Result b a
| (a or None) => Result None a

Documentation

A convenience method for the folktale/conversions/nullable-to-result module.

DEPRECATION WARNING:
In 2.0.x, fromNullable took only one parameter. This form of the method is now deprecated in favour of passing an explicit fallback value.

Example:

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

Result.fromNullable(1, 'error');
// ==> Result.Ok(1)

Result.fromNullable(null, 'error');
// ==> Result.Error('error')

Result.fromNullable(undefined, 'error');
// ==> Result.Error('error')

Properties

Source Code

Defined in source/result/index.js at line 18, column 17
fromNullable(aNullable, fallbackValue) {
    const nullableToResult = require('folktale/conversions/nullable-to-result');

    if (arguments.length > 1) {  // eslint-disable-line prefer-rest-params 
      return nullableToResult(aNullable, fallbackValue);
    } else {
      return nullableToResult(aNullable);
    }
  }
Licence
MIT
Module
folktale/result
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • Quildreen Motta
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)