nif_sorter v0.2.0 NifSorter View Source

NIF replacement for Enum.sort/1 for typed list of strings/numbers

Link to this section Summary

Functions

Sort typed list of floats in ascending order

Sort typed list of integers in ascending order

Sort typed list of strings/integers/floats in ascending order

Sort typed list of strings alphabetically in ascending order

Link to this section Types

Link to this type

supported_type()

View Source
supported_type() :: String.t() | integer() | float()

Link to this section Functions

Link to this function

float_sort(_)

View Source
float_sort([float()]) :: [float()]

Sort typed list of floats in ascending order

Examples

iex> NifSorter.float_sort([2.31, 2.07, 1.2, -10.4])
[-10.4, 1.2, 2.07, 2.31]
iex> NifSorter.int_sort([2, 1.14])
(ArgumentError) argument error
Link to this function

int_sort(_)

View Source
int_sort([integer()]) :: [integer()]

Sort typed list of integers in ascending order

Works for integers in range -9223372036854775808..9223372036854775807

Examples

iex> NifSorter.int_sort([2, 3, 1])
[1, 2, 3]
iex> NifSorter.int_sort([2, 1.14])
(ArgumentError) argument error

Sort typed list of strings/integers/floats in ascending order

This methods just auto-detects list type by first item. List still should be strictly typed.

Examples

iex> NifSorter.sort(["xir", "i", "el"])
["el", "i", "xir"]
iex> NifSorter.sort([2, 3, 1])
[1, 2, 3]
iex> NifSorter.sort([2.31, 2.07, 1.2, -10.4])
[-10.4, 1.2, 2.07, 2.31]
iex> NifSorter.sort([1, 2.2])
(ArgumentError) argument error

Sort typed list of strings alphabetically in ascending order

Examples

iex> NifSorter.str_sort(["xir", "i", "el"])
["el", "i", "xir"]
iex> NifSorter.str_sort(["aaa", 123])
(ArgumentError) argument error