View Source Colonel.Experimental (Colonel v0.2.0)

A proving ground for functions before they make it into Colonel proper.

Summary

Functions

Translates to left + right.

Translates to left && right.

Translates to left <> right.

Translates to left / right.

Translates to left == right.

Translates to left > right.

Translates to left >= right.

Translates to left != right.

Does the same thing as inspect/2 but returns IO data instead of a string.

Translates to left < right.

Translates to left <= right.

Translates to left ++ right.

Translates to left -- right.

Translates to left * right.

Translates to -value.

Translates to !value.

Translates to left || right.

Translates to +value.

Build a recursive anonymous function.

Handles the sigil ~i for iodata.

Translates to left === right.

Translates to left !== right.

Translates to left - right.

Functions

Link to this function

add(left, right)

View Source (since 0.1.0)
@spec add(integer(), integer()) :: integer()
@spec add(float(), float()) :: float()
@spec add(integer(), float()) :: float()
@spec add(float(), integer()) :: float()

Translates to left + right.

Examples

iex> add(1, 2)
3
Link to this function

and?(left, right)

View Source (since 0.1.0)
@spec and?(as_boolean(left), as_boolean(right)) :: as_boolean(left | right)
when left: term(), right: term()

Translates to left && right.

Examples

iex> and?(nil, false)
nil

iex> and?(1, nil)
nil

iex> and?(false, 2)
false

iex> and?(true, 2)
2
Link to this function

binary_concat(left, right)

View Source (since 0.1.0)
@spec binary_concat(binary(), binary()) :: binary()

Translates to left <> right.

Examples

iex> binary_concat("foo", "bar")
"foobar"
Link to this function

divide(left, right)

View Source (since 0.1.0)
@spec divide(number(), number()) :: float()

Translates to left / right.

Examples

iex> divide(1, 2)
0.5
Link to this function

equal?(left, right)

View Source (since 0.1.0)
@spec equal?(term(), term()) :: boolean()

Translates to left == right.

Examples

iex> equal?(1, 2)
false

iex> equal?(1, 1.0)
true
Link to this function

greater_than?(left, right)

View Source (since 0.1.0)
@spec greater_than?(term(), term()) :: boolean()

Translates to left > right.

Examples

iex> greater_than?(1, 2)
false
Link to this function

greater_than_or_equal?(left, right)

View Source (since 0.1.0)
@spec greater_than_or_equal?(term(), term()) :: boolean()

Translates to left >= right.

Examples

iex> greater_than_or_equal?(1, 2)
false
Link to this function

inequal?(left, right)

View Source (since 0.1.0)
@spec inequal?(term(), term()) :: boolean()

Translates to left != right.

Examples

iex> inequal?(1, 2)
true

iex> inequal?(1, 1.0)
false
Link to this function

iodata_inspect(term, opts \\ [])

View Source (since 0.2.0)
@spec iodata_inspect(
  Inspect.t(),
  keyword()
) :: iodata()

Does the same thing as inspect/2 but returns IO data instead of a string.

See "iodata and chardata".

Examples

iex> iodata_inspect(:foo)
[":foo"]

iex> iodata_inspect([1, 2, 3, 4, 5], limit: 3)
["[", "1", ",", " ", "2", ",", " ", "3", ",", " ", "...", "]"]

iex> iodata_inspect([1, 2, 3], pretty: true, width: 0)
["[", "1", ",", "\n ", "2", ",", "\n ", "3", "]"]

iex> iodata_inspect("olá" <> <<0>>)
["<<", "111", ",", " ", "108", ",", " ", "195", ",", " ", "161", ",", " ", "0", ">>"]

iex> iodata_inspect("olá" <> <<0>>, binaries: :as_strings)
[~S("olá\0")]

iex> iodata_inspect("olá", binaries: :as_binaries)
["<<", "111", ",", " ", "108", ",", " ", "195", ",", " ", "161", ">>"]

iex> iodata_inspect([0 | ~c"bar"])
["[", "0", ",", " ", "98", ",", " ", "97", ",", " ", "114", "]"]

iex> iodata_inspect(100, base: :octal)
["0o144"]

iex> iodata_inspect(100, base: :hex)
["0x64"]
Link to this function

less_than?(left, right)

View Source (since 0.1.0)
@spec less_than?(term(), term()) :: boolean()

Translates to left < right.

Examples

iex> less_than?(1, 2)
true
Link to this function

less_than_or_equal?(left, right)

View Source (since 0.1.0)
@spec less_than_or_equal?(term(), term()) :: boolean()

Translates to left <= right.

Examples

iex> less_than_or_equal?(1, 2)
true
Link to this function

list_concat(left, right)

View Source (since 0.1.0)
@spec list_concat(list(), term()) :: maybe_improper_list()

Translates to left ++ right.

Examples

iex> list_concat([1], [2, 3])
[1, 2, 3]
Link to this function

list_subtract(left, right)

View Source (since 0.1.0)
@spec list_subtract(list(), list()) :: list()

Translates to left -- right.

Examples

iex> list_subtract([1, 2, 3], [1, 2])
[3]
Link to this function

multiply(left, right)

View Source (since 0.1.0)
@spec multiply(integer(), integer()) :: integer()
@spec multiply(float(), float()) :: float()
@spec multiply(integer(), float()) :: float()
@spec multiply(float(), integer()) :: float()

Translates to left * right.

Examples

iex> multiply(1, 2)
2
Link to this function

negative(value)

View Source (since 0.1.0)
@spec negative(0) :: 0
@spec negative(pos_integer()) :: neg_integer()
@spec negative(neg_integer()) :: pos_integer()
@spec negative(float()) :: float()

Translates to -value.

Examples

iex> negative(2)
-2
Link to this function

not?(value)

View Source (since 0.1.0)
@spec not?(as_boolean(term())) :: boolean()

Translates to !value.

Examples

iex> not?(nil)
true

iex> not?(1)
false
Link to this function

or?(left, right)

View Source (since 0.1.0)
@spec or?(as_boolean(left), as_boolean(right)) :: as_boolean(left | right)
when left: term(), right: term()

Translates to left || right.

Examples

iex> or?(nil, false)
false

iex> or?(1, nil)
1

iex> or?(false, 2)
2

iex> or?(true, 2)
true
Link to this function

positive(value)

View Source (since 0.1.0)
@spec positive(integer()) :: integer()
@spec positive(float()) :: float()

Translates to +value.

Examples

iex> positive(1)
1
Link to this macro

recursive(fun)

View Source (since 0.1.0) (macro)

Build a recursive anonymous function.

This macro must be passed the function in the fn syntax.

Generated functions can call themselves using super.

Examples

iex> reverse = recursive fn
...>   [], acc -> acc
...>   [head | tail], acc -> super(tail, [head | acc])
...> end
iex> reverse.([1, 2, 3], [])
[3, 2, 1]
Link to this macro

sigil_i(term, modifiers)

View Source (since 0.2.0) (macro)

Handles the sigil ~i for iodata.

See "iodata and chardata".

Modifiers

  • s: interpolated values should be transformed by to_string/1 (default)
  • i: interpolated values should be transformed by iodata_inspect/1
  • d: interpolated values are already iodata/chardata and do not need transformed

Using the ~i sigil with the s or i modifiers will always return iodata. The d modifier allows for chardata that is not iodata by passing through interpolated chardata.

The d modifier

The d modifier does not transform interpolated values, so they will appear in the generated list as-is. This makes the operation cheaper when interpolated values are already iodata/chardata but allows construction of invalid iodata/chardata. Care should be taken when using the d modifier that all interpolated values are valid iodata/chardata.

Examples

iex> ~i"some #{["list", ["of", "nested"], "values"]} and #{:such}"
["some ", "listofnestedvalues", " and ", "such"]

iex> ~i"some #{["list", ["of", "nested"], "values"]} and #{:such}"s
["some ", "listofnestedvalues", " and ", "such"]

iex> ~i"some #{["list", ["of", "nested"], "values"]} and #{:such}"i
[
  "some ",
  [
    "[",
    "",
    ~S("list"),
    ",",
    " ",
    "[",
    ~S("of"),
    ",",
    " ",
    ~S("nested"),
    "]",
    ",",
    " ",
    ~S("values"),
    "",
    "]"
  ],
  " and ",
  [":such"]
]

iex> ~i"some #{["list", ["of", "nested"], "values"]} and #{to_string(:such)}"d
["some ", ["list", ["of", "nested"], "values"], " and ", "such"]
Link to this function

strictly_equal?(left, right)

View Source (since 0.1.0)
@spec strictly_equal?(term(), term()) :: boolean()

Translates to left === right.

Examples

iex> strictly_equal?(1, 2)
false

iex> strictly_equal?(1, 1.0)
false
Link to this function

strictly_inequal?(left, right)

View Source (since 0.1.0)
@spec strictly_inequal?(term(), term()) :: boolean()

Translates to left !== right.

Examples

iex> strictly_inequal?(1, 2)
true

iex> strictly_inequal?(1, 1.0)
true
Link to this function

subtract(left, right)

View Source (since 0.1.0)
@spec subtract(integer(), integer()) :: integer()
@spec subtract(float(), float()) :: float()
@spec subtract(integer(), float()) :: float()
@spec subtract(float(), integer()) :: float()

Translates to left - right.

Examples

iex> subtract(1, 2)
-1