nullableToResult

Converts a nullable value to a Result. null and undefined map to Errors, any other value maps to Oks.

Signature

nullableToResult(a)
forall a:
  (a or None) => Result None a

Documentation

Converts a nullable value to a Result. null and undefined map to Errors, any other value maps to Oks.

A nullable is a value that may be any type, or null/undefined.

Example:

const nullableToResult = require('folktale/conversions/nullable-to-result');
const { Error, Ok } = require('folktale/result');

nullableToResult(undefined);  // ==> Error(undefined)
nullableToResult(null);       // ==> Error(null)
nullableToResult(1);          // ==> Ok(1)

Properties

Source Code

Defined in source/conversions/nullable-to-result.js at line 22, column 0
(a) =>
  a != null ? Ok(a)
  :/*else*/   Error(a)
Stability
stable
Licence
MIT
Module
folktale/conversions/nullable-to-result
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • @boris-marinov
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)