LibLinq-1.0

Enumerable.prototype:ShuffleInPlace()

Randomizes the elements of the List in-place, thus changes the contents of the list.

Usage

list:ShuffleInPlace()


Enumerable.prototype:ToList()

Make a new List filled with the contents of the current Enumerable

Return value

a List


List.FromArguments(...)

Construct and return a new list based on the arguments provided

Parameters

...
a tuple of arguments to fill the list with

Return value

a List

Usage

local list = List.FromArguments()
local list = List.FromArguments(1, 2, 3)
local list = List.FromArguments(nil, nil, 5)


List.New(sequence)

Construct and return a new list

Parameters

sequence
optional: The sequence to fill the list with

Return value

a List

Usage

local list = List.New()
local list = List.New({ 1, 2, 3 })
local list = List.New(Enumerable.RangeTo(1, 10))


List.WrapTable(t)

Wrap a lua table such that there is parity between the passed-in table and the List.
Unlike other tables, this will not gracefully handle nils.

Parameters

t
the table to wrap around

Return value

a List

Usage

local list = List.WrapTable({ 1, 2, 3 })


List.prototype:Add(item)

Add an element to the List

Parameters

item
the element to add

Usage

list:Add(5)
list:Add(nil)


List.prototype:AddMany(...)

Add multiple elements to the current List

Parameters

...
zero or more arguments to add

Usage

list:AddMany(1, 2, 3)


List.prototype:AddRange(sequence)

Add a sequence of elements to the current List

Parameters

sequence
a sequence of elements to add

Usage

list:AddRange(Enumerable.RangeTo(1, 10))
list:AddRange({ 1, 2, 3 })


List.prototype:Clear()

Clear all elements from the List

Usage

list:Clear()


List.prototype:Clone()

Make a shallow clone of the List.
If the previous List was read-only, the clone will not be.

Usage

local other = list:Clone()


List.prototype:ConvertToReadOnly()

Make the List read-only, preventing any further modifications.
There is no way to convert a List back to being modifiable.

Return value

the same List that was made read-only

Usage

list:ConvertToReadOnly()


List.prototype:GetEnumerator()

Return an Enumerator for the current List

Return value

an Enumerator


List.prototype:Insert(index, item)

Insert an element into a position in the list.

Parameters

index
the position of the element. Cannot be less than 1 or greater than count+1
item
the element to insert

Usage

list:Insert(1, "hey")


List.prototype:InsertMany(index, ...)

Insert multiple arguments into a position in the list.

Parameters

index
the position of the sequence. Cannot be less than 1 or greater than count+1
...
zero or more arguments to add

Usage

list:InsertMany(1, "hey", "there")
list:InsertMany(1, 1, 2, 3, 4, 5)


List.prototype:InsertRange(index, sequence)

Insert a sequence into a position in the list.

Parameters

index
the position of the sequence. Cannot be less than 1 or greater than count+1
sequence
the sequence to insert

Usage

list:InsertRange(1, { "hey", "there" })
list:InsertRange(1, Enumerable.RangeTo(1, 5))


List.prototype:IsReadOnly()

Return whether the List is read-only, and thus cannot have modifications made to it.

Return value

a boolean

Usage

local read_only = list:IsReadOnly()


List.prototype:PickAndRemoveRandom()

Randomly pick a random element in the List, remove it, and return the value.
This will error if the List is empty.

Return value

a random value in the List

Usage

local value = list:PickAndRemoveRandom()


List.prototype:Remove(item)

Remove a given item from the list

Parameters

item
the item to remove

Return value

whether the item was successfully removed

Usage

local removed = list:Remove(5)


List.prototype:RemoveAt(index)

Remove an item from the list at the given index.

Parameters

index
the 1-based index to remove

Usage

list:RemoveAt(1)


List.prototype:RemoveRange(index, count)

Remove multiple elements from the List

Parameters

index
the starting 1-based index to remove
count
the amount of elements to remove


List.prototype:RemoveWhere(predicate)

Remove all elements which match a given predicate

Parameters

predicate
a function which is passed each element and should return true to remove, false to keep

Return value

the number of elements removed

Usage

local num = list:RemoveWhere(function(x) return x % 2 == 0 end)


List.prototype:ReplaceAt(index, item)

Replace an element at the given index.

Parameters

index
the 1-based index to replace. Must be at least 1 and no greater than the count+1
item
the item to add

Usage

List.New({ 1, 2 }):ReplaceAt(1, 3) -- [3, 2]
List.New({ 1, 2 }):ReplaceAt(3, 2) -- [1, 2, 3]


List.prototype:ReplaceMany(index, ...)

Replace a sequence of elements at the given index.

Parameters

index
the 1-based index to replace. Must be at least 1 and no greater than the count+1
...
zero or more arguments to add

Usage

List.New({ 1, 2 }):ReplaceMany(1, 3, 4) -- [3, 4]
List.New({ 1, 2 }):ReplaceMany(2, 3, 4) -- [1, 3, 4]
List.New({ 1, 2 }):ReplaceMany(3, 3, 4) -- [1, 2, 3, 4]


List.prototype:ReplaceRange(index, sequence)

Replace a sequence of elements at the given index.

Parameters

index
the 1-based index to replace. Must be at least 1 and no greater than the count+1
sequence
the sequence to add

Usage

List.New({ 1, 2 }):ReplaceRange(1, { 3, 4 }) -- [3, 4]
List.New({ 1, 2 }):ReplaceRange(2, { 3, 4 }) -- [1, 3, 4]
List.New({ 1, 2 }):ReplaceRange(3, { 3, 4 }) -- [1, 2, 3, 4]


List.prototype:ReverseInPlace()

Reverse the current List in-place, thus changing the contents of the list.

Usage

list:ReverseInPlace()


List.prototype:SetContract(contract)

Set a contract that will be verified against any existing elements and any added elements or changed values.
This is handy for if you want to verify that all values are strings or something like that. This will call :VerifyContract()

Parameters

contract
a function that is passed the element and should return whether the element is valid.

Usage

list:SetContract(function(v) return type(v) == "string" end)


List.prototype:Sort(comparer)

Sort the current List in-place based on the given comparison.

Parameters

comparer
a function which takes two elements and returns -1 if the first is less than the second, 1 for the opposite, and 0 if equivalent.

Usage

list:Sort(function(a, b) if #a < #b then return -1 elseif #a > #b then return 1 elseif a < b then return -1 elseif a > b then return 1 else return 0 end end)


List.prototype:VerifyContract()

Verify that the contract for this List is valid for all elements in the List.
If there is no contract, this does nothing.

Usage

list:VerifyContract()


You must login to post a comment. Don't have an account? Register to get one!

Table of contents

  1. 1 Enumerable.prototype:ShuffleInPlace()
    1. 1.1 Usage
  2. 2 Enumerable.prototype:ToList()
    1. 2.1 Return value
  3. 3 List.FromArguments(...)
    1. 3.1 Parameters
    2. 3.2 Return value
    3. 3.3 Usage
  4. 4 List.New(sequence)
    1. 4.1 Parameters
    2. 4.2 Return value
    3. 4.3 Usage
  5. 5 List.WrapTable(t)
    1. 5.1 Parameters
    2. 5.2 Return value
    3. 5.3 Usage
  6. 6 List.prototype:Add(item)
    1. 6.1 Parameters
    2. 6.2 Usage
  7. 7 List.prototype:AddMany(...)
    1. 7.1 Parameters
    2. 7.2 Usage
  8. 8 List.prototype:AddRange(sequence)
    1. 8.1 Parameters
    2. 8.2 Usage
  9. 9 List.prototype:Clear()
    1. 9.1 Usage
  10. 10 List.prototype:Clone()
    1. 10.1 Usage
  11. 11 List.prototype:ConvertToReadOnly()
    1. 11.1 Return value
    2. 11.2 Usage
  12. 12 List.prototype:GetEnumerator()
    1. 12.1 Return value
  13. 13 List.prototype:Insert(index, item)
    1. 13.1 Parameters
    2. 13.2 Usage
  14. 14 List.prototype:InsertMany(index, ...)
    1. 14.1 Parameters
    2. 14.2 Usage
  15. 15 List.prototype:InsertRange(index, sequence)
    1. 15.1 Parameters
    2. 15.2 Usage
  16. 16 List.prototype:IsReadOnly()
    1. 16.1 Return value
    2. 16.2 Usage
  17. 17 List.prototype:PickAndRemoveRandom()
    1. 17.1 Return value
    2. 17.2 Usage
  18. 18 List.prototype:Remove(item)
    1. 18.1 Parameters
    2. 18.2 Return value
    3. 18.3 Usage
  19. 19 List.prototype:RemoveAt(index)
    1. 19.1 Parameters
    2. 19.2 Usage
  20. 20 List.prototype:RemoveRange(index, count)
    1. 20.1 Parameters
  21. 21 List.prototype:RemoveWhere(predicate)
    1. 21.1 Parameters
    2. 21.2 Return value
    3. 21.3 Usage
  22. 22 List.prototype:ReplaceAt(index, item)
    1. 22.1 Parameters
    2. 22.2 Usage
  23. 23 List.prototype:ReplaceMany(index, ...)
    1. 23.1 Parameters
    2. 23.2 Usage
  24. 24 List.prototype:ReplaceRange(index, sequence)
    1. 24.1 Parameters
    2. 24.2 Usage
  25. 25 List.prototype:ReverseInPlace()
    1. 25.1 Usage
  26. 26 List.prototype:SetContract(contract)
    1. 26.1 Parameters
    2. 26.2 Usage
  27. 27 List.prototype:Sort(comparer)
    1. 27.1 Parameters
    2. 27.2 Usage
  28. 28 List.prototype:VerifyContract()
    1. 28.1 Usage

Facts

Date created
Aug 30, 2010
Last updated
Jan 14, 2011

Author