scalaz/scalaz — Issue #68: If functions
Author: tonymorris
Created: 2012-01-30 11:41:48+00:00
State: open

Some handy functions to write related to if-branching. The haskell version is below.

```haskell
import Data.Monoid

if' ::
(Eq p, Monoid p) =>
a
-> a
-> p
-> a
if' t f p =
if p == mempty then t else f

xif ::
(Eq p, Monoid p) =>
(a -> a)
-> p
-> a
-> a
xif =
if' id

ifx ::
(Eq p, Monoid p) =>
(a -> a)
-> p
-> a
-> a
ifx =
flip if' id

zif ::
(Eq p, Monoid p, Monoid a) =>
a
-> p
-> a
zif =
if' mempty

ifz ::
(Eq p, Monoid p, Monoid a) =>
a
-> p
-> a
ifz =
flip if' mempty
```