Skip to content

Commit

Permalink
Generic tuple based zip operations
Browse files Browse the repository at this point in the history
  • Loading branch information
lrleon committed Mar 21, 2021
1 parent 2eeb203 commit 64fa35b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion functional.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (tuple *Tuple) Traverse(f func(interface{}) bool) bool {
}

func (tuple *Tuple) Append(item interface{}, items ...interface{}) interface{} {
*tuple.l = append(*tuple.l, items)
*tuple.l = append(*tuple.l, item)
for _, i := range items {
*tuple.l = append(*tuple.l, i)
}
Expand Down
32 changes: 32 additions & 0 deletions functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,35 @@ func TestTZip(t *testing.T) {
return tuple.Nth(2) == i
}))
}

func TestTUnzip(t *testing.T) {

l1 := Seq.New(1, 2, 3, 4, 5)
l2 := Seq.New("A", "B", "C", "D", "E")
l3 := Seq.New(-5, -4, -3, -2, -1)

zl := TZip(l1, l2, l3)

tuple := TUnzip(zl)

assert.True(t, All(Zip(tuple.Nth(0).(*Seq.Slist), l1), func(p interface{}) bool {
pair := p.(Pair)
i1 := pair.Item1.(int)
i2 := pair.Item2.(int)
return i1 == i2
}))

assert.True(t, All(Zip(tuple.Nth(1).(*Seq.Slist), l2), func(p interface{}) bool {
pair := p.(Pair)
i1 := pair.Item1.(string)
i2 := pair.Item2.(string)
return i1 == i2
}))

assert.True(t, All(Zip(tuple.Nth(2).(*Seq.Slist), l3), func(p interface{}) bool {
pair := p.(Pair)
i1 := pair.Item1.(int)
i2 := pair.Item2.(int)
return i1 == i2
}))
}

0 comments on commit 64fa35b

Please sign in to comment.