New IterTools Functionality Discussion #50
Labels
enhancement
New feature or request
good first issue
Good for newcomers
help wanted
Extra attention is needed
This thread is for discussion new functionality to implement in IterTools. Please reply with suggestions for new functionality.
Here are some of the functions I am considering implementing. Some are more useful than others.
Single
Shuffle
Shuffle the elements in the iterable.
Filter RegEx
Filter for elements where the regular expression matches.
Permutations
All permutations of size
length
.Combinations
All combinations of size
length
.Combinations With Replacement
All combinations, with repeated elements, of size
length
.Multi
Unzip
Reverse of zip. E.g.: ['a', 1], ['b', 2], ['c', 3] => ['a', 'b', 'c'], [1, 2, 3]
Note: specify types.
Reduce
To Random Value
Reduce the iterable to any random value in the iterable.
PHP implementation example
To Nth
Reduce the iterable to the value at the nth position.
PHP implementation example
To Frequencies
Reduce the iterable to a frequency distribution showing how often each different value in the data occurs.
To String
Reduces to a string joining all elements.
PHP implementation example
Summary
Not All Match
True if not all the elements are true according to the predicate.
Is Empty
True if the iterable is empty.
PHP implementation example
All Equal
True if all elements of the iterable are equal.
Note: Consider maybe adding a strict parameter, or alternate method
allSame
.Are Permutations
True if iterables are permutations of each other.
PHP implementation example
Is Partitioned
Returns true if all elements of given collection that satisfy the predicate appear before all elements that don't.
PHP implementation example
Set
Difference
Compares first iterable against one or more other iterables and iterates the values in array that are not present in any of the other arrays.
Transform
Distribute
Distribute the elements of the iterable evenly into n smaller iterables. Ex: ([1, 2, 3, 4], 2) => [1, 3], [2, 4]
Divide
Divide the elements of the iterable evenly into n smaller iterables, maintaining order. Ex: ([1, 2, 3, 4], 2) => [1, 2], [3, 4]
Random
Choice
Generate random selections from an array of values.
If optional param
repetitions
not given then iterate infinitely.PHP implementation example
Coin Flip
Generate random coin flips (0 or 1).
If optional param
repetitions
not given then iterate infinitely.PHP implementation example
Bool
Generate random boolean values.
If optional param
repetitions
not given then iterate infinitely.Number
Generate random integer numbers.
If optional param
repetitions
not given then iterate infinitely.PHP implementation example
Percentage
Generate a random percentage between 0 and 1.
If optional param
repetitions
not given then iterate infinitely.PHP implementation example
RockPaperScissors
Generate random rock-paper-scissors hands.
Return values: "rock", "paper", "scissors".
If optional param
repetitions
not given then iterate infinitely.PHP implementation example
The text was updated successfully, but these errors were encountered: