API/Enumerable-Set

Enumerable.prototype:All(predicate)

Return whether all elements in the sequence satisfy a predicate

Parameters

predicate
a function that takes an element and the index and returns a boolean

Return value

a boolean whether all elements in the sequence satisfy a predicate

Usage

Enumerable.From({ 1, 2, 3 }):All(function(x) return x % 2 == 1 end) == false
Enumerable.From({ 1, 3, 5 }):All(function(x) return x % 2 == 1 end) == true
Enumerable.From({ 1, 3, 5 }):All("x => x%2 == 1") == true


Enumerable.prototype:Any(predicate)

Return whether any of the elements in the sequence satisfy a predicate, or the sequence has any elements

Parameters

predicate
optional: a function that takes an element and the index and returns a boolean

Return value

a boolean whether any of the elements in the sequence satisfy a predicate, or the sequence has any elements

Usage

Enumerable.Empty():Any() == false
Enumerable.From({ 1 }):Any() == true
Enumerable.From({ 1, 2, 3 }):Any(function(x) return x % 2 == 0 end) == true
Enumerable.From({ 1, 3, 5 }):Any(function(x) return x % 2 == 0 end) == false
Enumerable.From({ 1, 2, 3 }):Any("x => x%2 == 0") == true


Enumerable.prototype:Concat(second)

Concatenate two sequences

Parameters

second
The sequence to concatenate

Return value

an Enumerable

Usage

Enumerable.From({ 1, 2, 3 }):Concat({ 4, 5, 6 }):ToString() == "[1, 2, 3, 4, 5, 6]"


Enumerable.prototype:Contains(value)

Returns whether the sequence contains an element

Parameters

value
The element to check for

Return value

an Enumerable

Usage

Enumerable.From({ 1, 2, 3 }):Contains(2) == true
Enumerable.From({ 1, 2, 3 }):Contains(0) == false


Enumerable.prototype:DefaultIfEmpty(default)

Returns the elements in the sequence or a single default element if empty

Parameters

default
The default element to use

Return value

an Enumerable

Usage

Enumerable.Empty():DefaultIfEmpty(2):ToString() == "[2]"
Enumerable.From({ 1, 2, 3 }):DefaultIfEmpty(2):ToString() == "[1, 2, 3]"


Enumerable.prototype:Distinct(compare_selector)

Returns a sequence with unique elements

Parameters

compare_selector
optional: a function to use when comparing

Return value

an Enumerable

Usage

Enumerable.From({ 1, 1, 2, 3, 1, 2 }):Distinct():ToString() == "[1, 2, 3]"
Enumerable.From({ 1, 1, 2, 3, "1", "2" }):Distinct():ToString() == '[1, 2, 3, "1", "2"]'
Enumerable.From({ 1, 1, 2, 3, "1", "2" }):Distinct(tostring):ToString() == '[1, 2, 3]'


Enumerable.prototype:Except(second, compare_selector)

Returns the set difference between two sequences

Parameters

second
The sequence whose elements will be removed from the first sequence if found
compare_selector
optional: a function to use when comparing

Return value

an Enumerable

Usage

Enumerable.From({ 1, 2, 3, 4, 5 }):Except({ 2, 4 }):ToString() == "[1, 3, 5]"


Enumerable.prototype:Intersect(second, compare_selector)

Returns the set intersection between two sequences

Parameters

second
The sequence whose elements will be kept in the first sequence if found
compare_selector
optional: a function to use when comparing

Return value

an Enumerable

Usage

Enumerable.From({ 1, 2, 3, 4, 5 }):Intersect({ 0, 2, 4 }):ToString() == "[2, 4]"


Enumerable.prototype:SequenceEqual(second, compare_selector)

Return whether the sequences are equal by comparing the elements

Parameters

second
The other sequence to compare to
compare_selector
optional: a function to use when comparing

Return value

whether the sequences are equal

Usage

Enumerable.From({ 1, 2, 3 }):SequenceEqual({ 1, 2, 3 }) == true


Enumerable.prototype:Union(second, compare_selector)

Returns the set union between two sequences

Parameters

second
The sequence whose elements will be kept in the first sequence if found
compare_selector
optional: a function to use when comparing

Return value

an Enumerable

Usage

Enumerable.From({ 1, 2, 4, 5 }):Union({ 0, 2, 3, 4 }):ToString() == "[0, 1, 2, 3, 4, 5]"



Comments

Posts Quoted:
Reply
Clear All Quotes