implemented Empty in seq
This commit is contained in:
parent
0520386674
commit
bf371cf8a9
@ -44,6 +44,13 @@ func Size(s Seq) uint64 {
|
||||
}
|
||||
}
|
||||
|
||||
// Returns whether or not the given Seq is empty. This is accomplished using
|
||||
// FirstRest and NOT just by naively returning Size(s) == 0.
|
||||
func Empty(s Seq) bool {
|
||||
_, _, ok := s.FirstRest()
|
||||
return !ok
|
||||
}
|
||||
|
||||
// Returns the elements in the Seq as a slice. If the underlying Seq has any
|
||||
// implicit order to it that order will be kept. An empty Seq will return an
|
||||
// empty slice; nil is never returned. In general this completes in O(N) time.
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"github.com/mediocregopher/ginger/types"
|
||||
)
|
||||
|
||||
// Tests the FirstRest, Size, and ToSlice methods of a Seq
|
||||
// Tests the FirstRest, Size, Empty, and ToSlice methods of a Seq
|
||||
func testSeqGen(t *T, s Seq, ints []types.Elem) Seq {
|
||||
intsl := uint64(len(ints))
|
||||
for i := range ints {
|
||||
@ -18,8 +18,13 @@ func testSeqGen(t *T, s Seq, ints []types.Elem) Seq {
|
||||
assertValue(ok, true, t)
|
||||
assertValue(first, ints[i], t)
|
||||
|
||||
empty := Empty(s)
|
||||
assertValue(empty, false, t)
|
||||
|
||||
s = rest
|
||||
}
|
||||
empty := Empty(s)
|
||||
assertValue(empty, true, t)
|
||||
return s
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user