Skip to content

Commit

Permalink
Updated to new version Slist
Browse files Browse the repository at this point in the history
  • Loading branch information
lrleon committed Apr 13, 2021
1 parent 635bf5a commit f2b54a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
21 changes: 12 additions & 9 deletions functional.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Sequence interface {
Swap(other interface{}) interface{}
IsEmpty() bool
CreateIterator() interface{}
Create(items ...interface{}) interface{}
}

// Pair A pair of interfaces. Returned by Zip
Expand All @@ -42,6 +43,10 @@ func NewTuple(items ...interface{}) *Tuple {
return &tuple
}

func (tuple *Tuple) Create(items ...interface{}) interface{} {
return NewTuple(items...)
}

// BuildTuple Build a tuple for storing n elements
func BuildTuple(n int) *Tuple {
s := make([]interface{}, n, n)
Expand Down Expand Up @@ -251,12 +256,10 @@ func ForEach(seq Sequence, operation func(interface{})) interface{} {

// All Return true if all the elements of the sequence meets predicate
func All(seq Sequence, predicate func(interface{}) bool) bool {

return seq.Traverse(predicate)
}

func Exist(seq Sequence, predicate func(interface{}) bool) bool {

return !All(seq, func(i interface{}) bool {
return !predicate(i)
})
Expand Down Expand Up @@ -364,7 +367,7 @@ func Find(seq Sequence, predicate func(item interface{}) bool) interface{} {
return nil
}

// Return a sequence containing the first n items from the sequence
// Take Return a sequence containing the first n items from the sequence
func Take(seq Sequence, n int) *Seq.Slist {

ret := Seq.New()
Expand All @@ -376,7 +379,7 @@ func Take(seq Sequence, n int) *Seq.Slist {
return ret
}

// Return a sequence containing the items after the first n from the sequence
// Drop Return a sequence containing the items after the first n from the sequence
func Drop(seq Sequence, n int) *Seq.Slist {

ret := Seq.New()
Expand All @@ -391,7 +394,7 @@ func Drop(seq Sequence, n int) *Seq.Slist {
return ret
}

// Return f(in, ..., f(i2, f(i1, initVal) ... ))
// Foldl Return f(in, ..., f(i2, f(i1, initVal) ... ))
func Foldl(seq Sequence, initVal interface{},
f func(acu, item interface{}) interface{}) interface{} {

Expand All @@ -402,7 +405,7 @@ func Foldl(seq Sequence, initVal interface{},
return retVal
}

// Return the n-th item in the sequence. Return nil if n is negative o greater than seq.Size()
// Nth Return the n-th item in the sequence. Return nil if n is negative o greater than seq.Size()
func Nth(seq Sequence, n int) interface{} {

if n < 0 || n >= seq.Size() {
Expand All @@ -419,7 +422,7 @@ func Nth(seq Sequence, n int) interface{} {
return nil // it should not be reached!
}

// Return the position in the sequence of the first element satisfying predicate. If no element satisfies
// Position Return the position in the sequence of the first element satisfying predicate. If no element satisfies
// predicate then it returns -1
func Position(seq Sequence, predicate func(item interface{}) bool) int {

Expand All @@ -433,7 +436,7 @@ func Position(seq Sequence, predicate func(item interface{}) bool) int {
return -1
}

// Zip all the lists into a list of tuples
// TZip Zip all the lists into a list of tuples
func TZip(list *Seq.Slist, lists ...*Seq.Slist) *Seq.Slist {

sz := len(lists) + 1
Expand All @@ -459,7 +462,7 @@ func TZip(list *Seq.Slist, lists ...*Seq.Slist) *Seq.Slist {
return ret
}

// Unzip a list of tuples into a tuple of lists
// TUnzip Unzip a list of tuples into a tuple of lists
func TUnzip(tupleList *Seq.Slist) *Tuple {

tupleSize := tupleList.First().(*Tuple).Size()
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/geniussportsgroup/FunctionalLib
go 1.15

require (
github.com/geniussportsgroup/Slist v1.0.6
github.com/geniussportsgroup/treaps v1.1.8
github.com/geniussportsgroup/Slist v1.0.7
github.com/geniussportsgroup/treaps v1.2.1
github.com/stretchr/testify v1.7.0
)

0 comments on commit f2b54a7

Please sign in to comment.