Fakerjs.Data.Undefinable
- Package
- purescript-fakerjs
- Repository
- purescript-open-community/purescript-fakerjs
This module defines types and functions for working with undefinable types using the FFI.
#Undefinable Source
data Undefinable t0
A undefinable type. This type constructor is intended to be used for interoperating with JavaScript functions which accept or return undefined values.
The runtime representation of Undefinable T
is the same as that of T
,
except that it may also be undefined
. For example, the JavaScript values
undefined
, []
, and [1,2,3]
may all be given the type
Undefinable (Array Int)
. Similarly, the JavaScript values []
, [undefined]
,
and [1,2,undefined,3]
may all be given the type Array (Undefinable Int)
.
There is one pitfall with Undefinable
, which is that values of the type
Undefinable T
will not function as you might expect if the type T
happens
to itself permit undefined
as a valid runtime representation.
In particular, values of the type Undefinable (Undefinable T)
will ‘collapse’,
in the sense that the PureScript expressions notUndefined undefined
and undefined
will both leave you with a value whose runtime representation is just
undefined
. Therefore it is important to avoid using Undefinable T
in
situations where T
itself can take undefined
as a runtime representation.
If in doubt, use Maybe
instead.
Undefinable
does not permit lawful Functor
, Applicative
, or Monad
instances as a result of this pitfall, which is why these instances are
not provided.
Instances
(Show a) => Show (Undefinable a)
(Eq a) => Eq (Undefinable a)
Eq1 Undefinable
(Ord a) => Ord (Undefinable a)
Ord1 Undefinable
#undefined Source
undefined :: forall a. Undefinable a
The undefined value.
#notUndefined Source
notUndefined :: forall a. a -> Undefinable a
Wrap a non-undefined value.
#toMaybe Source
toMaybe :: forall a. Undefinable a -> Maybe a
Represent undefined
using Maybe a
as Nothing
. Note that this function
can violate parametricity, as it inspects the runtime representation of
its argument (see the warning about the pitfall of Undefinable
above).
#toUndefinable Source
toUndefinable :: forall a. Maybe a -> Undefinable a
Takes Nothing
to undefined
, and Just a
to a
.