Skip to content

Commit

Permalink
Pairwise
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonbot committed Nov 29, 2024
1 parent 0e58d6b commit bc05ac5
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions combinatorics.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,16 @@ func CombinationsOfLength[T any](vals []T, length int) iter.Seq[[]T] {
func Combinations[T any](vals []T) iter.Seq[[]T] {
return CombinationsOfLength(vals, len(vals))
}

// Pairwise will yield all possible combinations of the two slices
func Pairwise[T, V any](vals1 []T, vals2 []V) iter.Seq2[T, V] {
return func(yield func(T, V) bool) {
for _, t := range vals1 {
for _, v := range vals2 {
if !yield(t, v) {
return
}
}
}
}
}

0 comments on commit bc05ac5

Please sign in to comment.