Data.Nullable
- Package
- purescript-nullable
- Repository
- purescript-contrib/purescript-nullable
This module defines types and functions for working with nullable types using the FFI.
#Nullable Source
data Nullable t0A nullable type. This type constructor is intended to be used for interoperating with JavaScript functions which accept or return null values.
The runtime representation of Nullable T is the same as that of T,
except that it may also be null. For example, the JavaScript values
null, [], and [1,2,3] may all be given the type
Nullable (Array Int). Similarly, the JavaScript values [], [null],
and [1,2,null,3] may all be given the type Array (Nullable Int).
There is one pitfall with Nullable, which is that values of the type
Nullable T will not function as you might expect if the type T happens
to itself permit null as a valid runtime representation.
In particular, values of the type Nullable (Nullable T) will ‘collapse’,
in the sense that the PureScript expressions notNull null and null
will both leave you with a value whose runtime representation is just
null. Therefore it is important to avoid using Nullable T in
situations where T itself can take null as a runtime representation.
If in doubt, use Maybe instead.
Nullable does not permit lawful Functor, Applicative, or Monad
instances as a result of this pitfall, which is why these instances are
not provided.
Instances
#toNullable Source
toNullable :: forall a. Maybe a -> Nullable aTakes Nothing to null, and Just a to a.
- Modules
- Data.
Nullable