Mandrake v0.0.2 Mandrake.List

Mandrake mathematical functions.

Summary

Functions

Returns a new list after appending the new element

Returns the best item in a list based on the return value for the iterator function

Returns the best item in a list based on the return value for the iterator function

Returns true if list contains the given value

Returns a new list without the given item

Returns a new list without the given item

Returns the difference of the 2 lists

Returns true if all elements in a list are equal

Returns the first item of a list that returns true for the function

Returns a new list after applying the given function to each element of the list

Returns a new list starting from the given value or nil

Returns the intersection of the 2 lists

Returns the last item of a list that returns true for the function

Returns a list containing the given value

Returns a list of 2 lists. The first contains the elements that satisfy the function, other elements are in the second

Returns a list of 2 lists. The first contains the elements that satisfy the function, other elements are in the second

Returns a list composed by the value of the properties for the given key from items in the given list

Returns a list composed by the value of the properties for the given key from items in the given list

Returns a new list after prepending the new element

Returns a new list with the only item that satisfy the given function

Returns the list of items that satisfy the condition

Returns the extension of the first list with the second

Returns a list of items until the condition is true

Returns a list of items until the condition is true

Functions

append(element, list)

Returns a new list after appending the new element.

Examples

iex>  Mandrake.List.append(45, [4, 7, 43, 6, 3, 7])
[4, 7, 43, 6, 3, 7, 45]
best(function)

Returns the best item in a list based on the return value for the iterator function.

Examples

iex>  longest = Mandrake.List.best(fn arg1, arg2 -> if arg1 > arg2 do arg1 else arg2 end end)
...>  longest.([4, 7, 43, 6, 3, 7])
43
best(function, list)

Returns the best item in a list based on the return value for the iterator function.

Examples

iex>  Mandrake.List.best(fn arg1, arg2 -> if arg1 > arg2 do arg1 else arg2 end end, [4, 7, 43, 6, 3, 7])
43
contains(value, list)

Returns true if list contains the given value.

Examples

iex>  Mandrake.List.contains(3, [1, 2, 3, 4, 5])
true
delete(item)

Returns a new list without the given item.

Examples

iex>  delete_4 = Mandrake.List.delete(4)
...>  delete_4.([1, 2, 4, 3, 4, 5, 6])
[1, 2, 3, 5, 6]
delete(list, item)

Returns a new list without the given item.

Examples

iex>  Mandrake.List.delete([1, 2, 4, 3, 4, 5, 6], 4)
[1, 2, 3, 5, 6]
difference(first_list, second_list)

Returns the difference of the 2 lists.

Examples

iex>  Mandrake.List.difference([1, 2, 3], [2])
[1, 3]
equals(list)

Returns true if all elements in a list are equal.

Examples

iex>  Mandrake.List.equals([7, 7, 7])
true
first(func, list)

Returns the first item of a list that returns true for the function.

Examples

iex>  printHello = Mandrake.List.first(fn x -> Kernel.rem(x, 2) == 0 end, [2, 4, 5, 7])
2
for_each(function, list)

Returns a new list after applying the given function to each element of the list.

Examples

iex>  Mandrake.List.for_each(fn x -> x + 1 end, [1, 2, 3])
[2, 3, 4]
from(value, list)

Returns a new list starting from the given value or nil.

Examples

iex>  Mandrake.List.from(43, [4, 7, 43, 6, 3, 7])
[43, 6, 3, 7]
intersection(first_list, second_list)

Returns the intersection of the 2 lists.

Examples

iex>  Mandrake.List.intersection([1,2,3,4], [7,6,5,4,3])
[3, 4]
last(func, list)

Returns the last item of a list that returns true for the function.

Examples

iex>  Mandrake.List.last(fn x -> Kernel.rem(x, 2) == 0 end, [2, 4, 5, 7, 8, 9])
8
of(value)

Returns a list containing the given value.

Examples

iex>  Mandrake.List.of("Example")
["Example"]
partition(function)

Returns a list of 2 lists. The first contains the elements that satisfy the function, other elements are in the second.

Examples

iex>  even = Mandrake.List.partition(fn item -> Kernel.rem(item, 2) == 0 end)
...>  even.([4, 7, 43, 6, 3, 7])
[[4, 6], [7, 43, 3, 7]]
partition(function, list)

Returns a list of 2 lists. The first contains the elements that satisfy the function, other elements are in the second.

Examples

iex>  Mandrake.List.partition(fn item -> Kernel.rem(item, 2) == 0 end, [4, 7, 43, 6, 3, 7])
[[4, 6], [7, 43, 3, 7]]
pluck(key)

Returns a list composed by the value of the properties for the given key from items in the given list.

Examples

iex>  pluck_example = Mandrake.List.pluck(:example)
...>  pluck_example.([%{ name: "Doe" }, %{ example: "first", name: "John" }, %{ example: "second" }])
[ "first", "second" ]
pluck(list, key)

Returns a list composed by the value of the properties for the given key from items in the given list.

Examples

iex>  Mandrake.List.pluck([%{ name: "Doe" }, %{ example: "first", name: "John" }, %{ example: "second" }], :example)
[ "first", "second" ]
prepend(element, list)

Returns a new list after prepending the new element.

Examples

iex>  Mandrake.List.prepend(45, [4, 7, 43, 6, 3, 7])
[45, 4, 7, 43, 6, 3, 7]
select(function)

Returns a new list with the only item that satisfy the given function.

Examples

iex>  select_even = Mandrake.List.select(fn item -> Kernel.rem(item, 2) == 0 end)
...>  select_even.([2, 6, 7, 8, 10])
[2, 6, 8, 10]
select(function, list)

Returns the list of items that satisfy the condition.

Examples

iex>  Mandrake.List.select(fn item -> Kernel.rem(item, 2) == 0 end, [2, 6, 7, 8, 10])
[2, 6, 8, 10]
union(first_list, second_list)

Returns the extension of the first list with the second.

Examples

iex>  Mandrake.List.union([1, 2, 3], [4, 5])
[1, 2, 3, 4, 5]
while(function)

Returns a list of items until the condition is true.

Examples

iex>  while_even = Mandrake.List.while(fn item -> Kernel.rem(item, 2) == 0 end)
...>  while_even.([2, 6, 7, 8, 10])
[2, 6]
while(function, list)

Returns a list of items until the condition is true.

Examples

iex>  Mandrake.List.while(fn item -> Kernel.rem(item, 2) == 0 end, [2, 6, 7, 8, 10])
[2, 6]