Skip to content

Commit

Permalink
Renamed Pair type for json compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
lrleon committed Mar 20, 2021
1 parent 203f2a6 commit dac3ea2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions functional.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{} {

Expand Down Expand Up @@ -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 {

Expand All @@ -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()
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}))
}

Expand All @@ -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)
Expand Down Expand Up @@ -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)
}))
}

Expand Down

0 comments on commit dac3ea2

Please sign in to comment.