From dac3ea27ba09370f45984821393e322692ab20b5 Mon Sep 17 00:00:00 2001 From: lrleon Date: Sat, 20 Mar 2021 17:54:56 -0500 Subject: [PATCH] Renamed Pair type for json compatibility --- functional.go | 16 ++++++++-------- functional_test.go | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/functional.go b/functional.go index 52e9eec..c7f5caf 100644 --- a/functional.go +++ b/functional.go @@ -18,6 +18,10 @@ type Sequence interface { CreateIterator() interface{} } +type Pair struct { + Item1, Item2 interface{} +} + // Execute operation receiving every item of the sequence. Return seq func ForEach(seq Sequence, operation func(interface{})) interface{} { @@ -80,10 +84,6 @@ func Filter(seq Sequence, predicate func(interface{}) bool) *Seq.Slist { return ret } -type Pair struct { - item1, item2 interface{} -} - // Zip two lists into one list of pair. The result is truncated to the shortest list func Zip(s1, s2 Sequence) *Seq.Slist { @@ -93,8 +93,8 @@ func Zip(s1, s2 Sequence) *Seq.Slist { for it1.HasCurr() && it2.HasCurr() { ret.Append(Pair{ - item1: it1.GetCurr(), - item2: it2.GetCurr(), + Item1: it1.GetCurr(), + Item2: it2.GetCurr(), }) it1.Next() @@ -113,8 +113,8 @@ func Unzip(seq *Seq.Slist) (*Seq.Slist, *Seq.Slist) { for it := seq.CreateIterator().(*Seq.Iterator); it.HasCurr(); it.Next() { curr := it.GetCurr().(Pair) - l1.Append(curr.item1) - l2.Append(curr.item2) + l1.Append(curr.Item1) + l2.Append(curr.Item2) } return l1, l2 diff --git a/functional_test.go b/functional_test.go index f076fb8..f18e57b 100644 --- a/functional_test.go +++ b/functional_test.go @@ -78,7 +78,7 @@ func TestMap(t *testing.T) { assert.True(t, All(Zip(tree, m), func(i interface{}) bool { p := i.(Pair) - return 2*p.item1.(int) == p.item2.(int) + return 2*p.Item1.(int) == p.Item2.(int) })) } @@ -93,7 +93,7 @@ func TestZipUnzip(t *testing.T) { assert.True(t, All(lzip, func(i interface{}) bool { p := i.(Pair) - return p.item1 == p.item2 + return p.Item1 == p.Item2 })) r1, r2 := Unzip(lzip) @@ -138,7 +138,7 @@ func TestMapIf(t *testing.T) { assert.True(t, All(Zip(lmap, Filter(tree, pred)), func(i interface{}) bool { p := i.(Pair) - return p.item1.(int) == 2*p.item2.(int) + return p.Item1.(int) == 2*p.Item2.(int) })) }