base-compat-0.14.1: A compatibility layer for base

Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.Bool.Compat

Synopsis

- module Data.Bool
- bool :: a -> a -> Bool -> a

# Documentation

module Data.Bool

bool :: a -> a -> Bool -> a Source #

Case analysis for the `Bool` type. ``bool` f t p` evaluates to `f` when `p` is `False`, and evaluates to `t` when `p` is `True`.

This is equivalent to `if p then t else f`; that is, one can think of it as an if-then-else construct with its arguments reordered.

#### Examples

Expand

Basic usage:

    >>> bool "foo" "bar" True
    "bar"
    >>> bool "foo" "bar" False
    "foo"

Confirm that ``bool` f t p` and `if p then t else f` are equivalent:

    >>> let p = True; f = "bar"; t = "foo"
    >>> bool f t p == if p then t else f
    True
    >>> let p = False
    >>> bool f t p == if p then t else f
    True

Since: base-4.7.0.0