nullableToMaybe

Converts a nullable value to a maybe. null and undefined map to Nothing, any other value maps to Justs.

Signature

nullableToMaybe(a)
forall a:
  (a or None) => Maybe a

Documentation

Converts a nullable value to a maybe. null and undefined map to Nothing, any other value maps to Justs.

A nullable is a value that may be any type, or null/undefined. Since Nothing can't hold values, it's not possible to differentiate whether the original value was null or undefined after the conversion.

Example:

const nullableToMaybe = require('folktale/conversions/nullable-to-maybe');
const { Nothing, Just } = require('folktale/maybe');

nullableToMaybe(undefined);  // ==> Nothing()
nullableToMaybe(null);       // ==> Nothing()
nullableToMaybe(1);          // ==> Just(1)

Properties

Source Code

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