Wannabe Bool v0.1.1 WannabeBool protocol View Source

WannabeBool protocol is responsible for converting a structure to a boolean value.

The only function required to be implemented is to_boolean/1, which does the conversion.

The is_boolean/1 function is implemented for Atom, BitString, Integer and Float.

Link to this section Summary

Functions

Converts term to a boolean.

Link to this section Types

Link to this section Functions

Link to this function

to_boolean(term)

View Source
to_boolean(term()) :: boolean()

Converts term to a boolean.

Examples

iex> import WannabeBool
iex>
iex> to_boolean("true")
true
iex> to_boolean("false")
false
iex> to_boolean(:t)
true
iex> to_boolean(:f)
false
iex> to_boolean(1)
true
iex> to_boolean(0)
false
iex> to_boolean(1.0)
true
iex> to_boolean(0.0)
false