exlist v0.1.2 Exlist.Lists

Extension to lists functions

Summary

Functions

adds the given element elem to the end of the list list

adds the list to end of the given list as a list or list of items based on the boolean true or false respectively

Deletes the elements after the given elem in the given list

Deletes the elements before the given elem in the given list

Deletes the first elem in the given list

Deletes the last element in the given list

Flattens the given list and returns the sum of those elements

Returns the first occurrence of the elem in the list. Even if the multiple elements of same type presents, it returns only the first occurrence of the elem. If the element is not present in the list then it returns the nil

Returns the all occurrence of the elem in the list in the form list If the element is not present in the list then it returns empty list[]

Returns the given number of elements in the list. If the number passed is greater than or equal to the length of the list it returns the entire list

adds the given element elem to the begining of the list list

adds the list to begining of the given list as a list or list of items based on the boolean true or false respectively

Functions

append(list, elem)

Specs

append(list, any) :: list

adds the given element elem to the end of the list list

Examples

iex> Exlist.Lists.append []
nil

iex> Exlist.Lists.append [1,2,3],4
[1,2,3,4]

iex> Exlist.Lists.append [1,2,3],:atom
[1,2,3, :atom]

iex> Exlist.Lists.append [1,2,3],%{name: "john"}
[1, 2, 3, %{name: "john"}]
append(list1, list2, mode \\ false)

Specs

append(list, list, boolean) :: list

adds the list to end of the given list as a list or list of items based on the boolean true or false respectively

Examples

iex> Exlist.Lists.append [1,2,3],[4,5,6]
[1,2,3,[4,5,6]]

iex> Exlist.Lists.append [1,2,3],[4,5,6],:false 
[1,2,3,[4,5,6]]

iex> Exlist.Lists.append [1,2,3],[4,5,6], :true
[1,2,3,4,5,6]
delete_after(list, elem)

Specs

delete_after(list, any) :: list

Deletes the elements after the given elem in the given list

Examples

iex> Exlist.Lists.delete_after([1,2,3,4,5],2)
[1,2]
iex> Exlist.Lists.delete_after([1,2,3,4,5],10)
[1,2,3,4,5]
iex> Exlist.Lists.delete_after([1,2,[9,5],3,4,5],[9,5])
[1,2,[9,5]]
iex> Exlist.Lists.delete_after([1,2,%{type: :numbers},3,4,5],%{type: :numbers})
[1,2,%{type: :numbers}]
delete_before(list, elem)

Specs

delete_before(list, any) :: list

Deletes the elements before the given elem in the given list

Examples

iex> Exlist.Lists.delete_before([1,2,3,4,5],2)
[2,3,4,5]
iex> Exlist.Lists.delete_before([1,2,3,4,5],10)
[1,2,3,4,5]
iex> Exlist.Lists.delete_before([1,2,[9,5],3,4,5],[9,5])
[[9,5],3,4,5]
iex> Exlist.Lists.delete_before([1,2,%{type: :numbers},3,4,5],%{type: :numbers})
[%{type: :numbers},3,4,5]
delete_first(list)

Specs

delete_first([any]) :: list

Deletes the first elem in the given list

Examples

iex> Exlist.Lists.delete_first([1,3,5,7,9])
[3,5,7,9]
delete_last(list)

Specs

delete_last([any]) :: list

Deletes the last element in the given list

Examples

iex> Exlist.Lists.delete_last([1,3,5,7,9])
[1,3,5,7]
flat_sum(list)

Specs

flat_sum([number]) :: number

Flattens the given list and returns the sum of those elements

Examples

iex> Exlist.Lists.flat_sum [1,2,3,4,[5,6,7,[8,9,0]]]
45
index_of(list, elem)

Specs

index_of(list, any) :: integer

Returns the first occurrence of the elem in the list. Even if the multiple elements of same type presents, it returns only the first occurrence of the elem. If the element is not present in the list then it returns the nil

Examples

iex> Exlist.Lists.index_of [1,2,3,4,5],4
3
iex> Exlist.Lists.index_of [1,2,3,4,5],33
nil
iex> Exlist.Lists.index_of [1,2,3,3,4,3,5],3
2
indexes(list, elem)

Returns the all occurrence of the elem in the list in the form list If the element is not present in the list then it returns empty list[]

Examples

iex> Exlist.Lists.indexes [1,2,3,4,5],4
[3]
iex> Exlist.Lists.indexes [1,2,3,4,5],33
[]
iex> Exlist.Lists.indexes [1,2,3,3,4,3,5],3
[2,3,5]
list_get(list, num, option \\ :first)

Returns the given number of elements in the list. If the number passed is greater than or equal to the length of the list it returns the entire list.

How ever you have an option to pass how to get the elements.By default it returns the elements from the first.

If you want to get the elements to be returned from the last means you can pass an option as :last . The default option is :first

Examples

iex> Exlist.Lists.list_get([1,2,3,4,5],3)
[1,2,3]
iex> Exlist.Lists.list_get([1,2,3,4,5],3,:first)
[1,2,3]
iex> Exlist.Lists.list_get([1,2,3,4,5],3,:last)
[3,4,5]
prepend(list, elem)

Specs

prepend(list, any) :: list

adds the given element elem to the begining of the list list

Examples

iex> Exlist.Lists.prepend []
nil

iex> Exlist.Lists.prepend [1,2,3],4
[4,1,2,3]

iex> Exlist.Lists.prepend [1,2,3],:atom
[:atom,1,2,3]

iex> Exlist.Lists.prepend [1,2,3],%{name: "john"}
[%{name: "john"},1, 2, 3]
prepend(list1, list2, mode \\ false)

Specs

prepend(list, list, boolean) :: list

adds the list to begining of the given list as a list or list of items based on the boolean true or false respectively

Examples

iex> Exlist.Lists.prepend [1,2,3],[4,5,6]
[[4,5,6],1,2,3]

iex> Exlist.Lists.prepend [1,2,3],[4,5,6],:false 
[[4,5,6],1,2,3]

iex> Exlist.Lists.prepend [1,2,3],[4,5,6], :true
[4,5,6,1,2,3]