From 64fa35b73c687494edc61b570893c866452ea1fe Mon Sep 17 00:00:00 2001 From: lrleon Date: Sun, 21 Mar 2021 13:25:29 -0500 Subject: [PATCH] Generic tuple based zip operations --- functional.go | 2 +- functional_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/functional.go b/functional.go index 6e50028..81dedb7 100644 --- a/functional.go +++ b/functional.go @@ -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) } diff --git a/functional_test.go b/functional_test.go index e43b17a..9e862af 100644 --- a/functional_test.go +++ b/functional_test.go @@ -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 + })) +}