gloop is a Go utility library for convenient looping using Go's range-over-func feature.
Install gloop using the go get command:
go get -u github.com/alvii147/gloopNote
Go version 1.23+ required as older versions don't offer the range-over-func feature.
Once installed, gloop can be imported and used directly in your project:
package main
import (
	"fmt"
	"github.com/alvii147/gloop"
)
func main() {
	for seq := range gloop.Permutations(gloop.String("CAT"), 3) {
		perm := gloop.ToString(seq)
		fmt.Println(perm)
	}
}This ranges over and outputs all permutations of CAT:
CAT
CTA
ACT
ATC
TCA
TAC
See more specific documentation and examples in the features section below.
- Intervalallows looping over values in a given interval of a given step size.
- Linspaceallows looping over evenly spaced values within a given interval. n must be greater than 1.
- RandomNormalallows looping over a given number of random values drawn from a Gaussian distribution. The size must not be negative and the standard deviation must be positive.
- RandomUniformallows looping over a given number of random values drawn from a uniform distribution. The size must not be negative.
- Chainallows looping over multiple iter.Seq sequences.
- Chain2allows looping over multiple iter.Seq2 sequences.
- Channelallows looping over values from a given channel. The values are consumed from the channel.
- Collectallows looping over a given set of values.
- Enumerateallows looping over an iter.Seq sequence with an index, converting it to an iter.Seq2 sequence.
- Filterruns a given function on each value from an iter.Seq sequence and allows looping over values for which the function returns true.
- Filter2runs a given function on each value from an iter.Seq2 sequence and allows looping over values for which the function returns true.
- Keysallows looping over an iter.Seq2, converting it to an iter.Seq sequence by discarding the value.
- KeyValueconverts an iter.Seq sequence of [KeyValuePair] values to an iter.Seq2 sequence.
- KeyValue2converts an iter.Seq2 sequence to an iter.Seq sequence of [KeyValuePair] values.
- Listallows looping over a given container/list.List.
- Mapallows looping over keys and values in a map.
- Reverseallows looping over an iter.Seq sequence in order of descending index.
- Reverse2allows looping over an iter.Seq2 sequence in order of descending index.
- Sliceallows looping over a given slice.
- Sortallows looping over an iter.Seq sequence in sorted order.
- SortByComparisonallows looping over an iter.Seq sequence in sorted order using a comparison function.
- SortByComparison2allows looping over an iter.Seq2 sequence in sorted order using a comparison function.
- SortByRankallows looping over an iter.Seq sequence in sorted order using a ranking function.
- SortByRank2allows looping over an iter.Seq2 sequence in sorted order using a ranking function.
- Stringallows looping over the runes in a given string.
- Transformruns a given function on each value over an iter.Seq sequence and allows looping over the returned values.
- Transform2runs a given function on each key and value over an iter.Seq2 sequence and allows looping over the returned values.
- Uniqueallows looping over unique values in an iter.Seq sequence.
- Unique2allows looping over unique key value pairs in an iter.Seq2 sequence.
- Valuesallows looping over an iter.Seq2 and converting it to an iter.Seq sequence by discarding the key.
- Zipallows looping over two iter.Seq sequences in pairs.
- Zip2allows looping over two iter.Seq2 sequences in pairs.
- Batchallows looping over an iter.Seq sequence in batches of a given size. The batch size must be positive.
- Batch2allows looping over an iter.Seq2 sequence in batches of a given size. The batch size must be positive.
- CartesianProductallows looping over the Cartesian product of a given size for an iter.Seq sequence. The size must be positive.
- CartesianProduct2allows looping over the Cartesian product of a given size for an iter.Seq2 sequence. The size must be positive.
- Combinationsallows looping over all combinations of a given size for an iter.Seq sequence. The size must be positive.
- Combinations2allows looping over all combinations of a given size for an iter.Seq2 sequence. The size must be positive.
- Permutationsallows looping over all permutations of a given size for an iter.Seq sequence. The size must be positive.
- Permutations2allows looping over all permutations of a given size for an iter.Seq2 sequence. The size must be positive.
- Windowallows looping over an iter.Seq sequence in sliding windows of a given size.
- Window2allows looping over an iter.Seq2 sequence in sliding windows of a given size.
- ZipNallows looping over multiple iter.Seq sequences simultaneously.
- ZipN2allows looping over multiple iter.Seq2 sequences simultaneously.
- Allcomputes whether or not all values in an iter.Seq sequence are true.
- Anycomputes whether or not any value in an iter.Seq sequence is true.
- Equalchecks if two given iter.Seq sequences are exactly equal in contents and order.
- Equal2checks if two given iter.Seq2 sequences are exactly equal in contents and order.
- Equivalentchecks if two given iter.Seq sequences are equal in contents, ignoring order.
- Equivalent2checks if two given iter.Seq2 sequences are equal in contents, ignoring order.
- Foldruns a given function on each value from an iter.Seq sequence and accumulates the result into a single value.
- Fold2runs a given function on each value from an iter.Seq2 sequence and accumulates the result into a single value.
- Maxcomputes the maximum value over an iter.Seq sequence.
- MaxByComparisoncomputes the maximum value over an iter.Seq sequence using a comparison function.
- MaxByComparison2computes the maximum key and value over an iter.Seq2 sequence using a comparison function.
- MaxByRankcomputes the maximum value over an iter.Seq sequence using a ranking function.
- MaxByRank2computes the maximum value over an iter.Seq2 sequence using a ranking function.
- Meancomputes the mean value over an iter.Seq sequence.
- Mincomputes the minimum value over an iter.Seq sequence.
- MinByComparisoncomputes the minimum value over an iter.Seq sequence using a comparison function.
- MinByComparison2computes the minimum key and value over an iter.Seq2 sequence using a comparison function.
- MinByRankcomputes the minimum value over an iter.Seq sequence using a ranking function.
- MinByRank2computes the minimum value over an iter.Seq2 sequence using a ranking function.
- Productcomputes the product of values over an iter.Seq sequence.
- Reduceruns a given function on each adjacent pair in an iter.Seq sequence and accumulates the result into a single value.
- Reduce2runs a given function on each adjacent pair of keys and values in an iter.Seq2 sequence and accumulates the result into a single key and value pair.
- Sumcomputes summation over an iter.Seq sequence.
- ToListconverts an iter.Seq sequence to a container/list.List.
- ToList2converts an iter.Seq2 sequence to container/list.List of keys and values.
- ToSliceconverts an iter.Seq sequence to a slice.
- ToSlice2converts an iter.Seq2 sequence to slices of keys and values.
- ToStringconverts an iter.Seq sequence of runes to a string.
- DeferLoopallows looping over an iter.Seq sequence, yielding a defer function that can register another function to be executed at the end of the currently running loop. If multiple functions are registered, they are executed in FIFO order.
- Parallelizeruns a function on each value in an iter.Seq sequence on separate goroutines.
- Parallelize2runs a function on each value in an iter.Seq2 sequence on separate goroutines.
All contributions are welcome! Please see CONTRIBUTING.md for contribution guidelines.