IsNull-0.4.0.0: A typeclass to determine if a given value is null.

Maintainerjmacristovao@gmail.com
Safe HaskellNone

Data.IsNull

Description

A typeclass to determine if a given value is null.

Strongly inspired by mono-traversable but with a simpler goal: supporting IsNull and nested IsNull operations.

While the isNull function is equivalent to (==) mempty for most of the instances, not all Foldables are monoids, and not all monoids mempty means null:

  • Either is an example of a Foldable which is not a Monoid, but where it makes sense to consider a Left as an Null value. While this is not strictly true, the Left option does carries a value, we take the more liberal approach: Empty ~ Null ~ Invalid Value. If you need proper type reasoning, you should not be using this package, just regular pattern matching instead.
  • Product Monoid instance is 1. Hardly qualifies as an Empty or Null value. For this reason no default implementation is provided for the Monoid class. It's up to you to use (==) mempty instead.

This class is suitable for use with GeneralizedNewtypeDeriving, thanks to the precious help of Ivan Miljenovic.

Bugs, suggestions and comments are most welcomed!

https://github.com/jcristovao/IsNull

Synopsis

Documentation

class IsNull a whereSource

Methods

isNull :: a -> BoolSource

isNull ~ isEmpty ~ isInvalid?

>>> isNull (Left 5)
True
>>> isNull ("abc" :: T.Text)
False
>>> isNull [""] -- see isNullN
False

notNull :: IsNull a => a -> BoolSource

the logical negation of isNull

isNullN :: (IsNull a, Foldable f) => f a -> BoolSource

Nested isNull

>>> isNullN (Just "abc")
False
>>> isNullN (Just "")
True
>>> isNullN (Nothing :: Maybe String)
True

notNullN :: (IsNull a, Foldable f) => f a -> BoolSource

Nested isNotNull

isNullM :: (IsNull a, Functor m) => m a -> m BoolSource

Monadic isNull

>>> isNullM [""]
[True]

isNullNM :: (IsNull a, Functor m, Foldable f) => m (f a) -> m BoolSource

Monadic Nested isNull

(<\>) :: IsNull a => a -> a -> aSource