aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2019-03-06 18:42:56 -0700
committerGitHub <noreply@github.com>2019-03-06 18:42:56 -0700
commit549186e069824239fa3b0677b8b90cdfa2c21c48 (patch)
treefdcdb01e938416a2de9aa1646844aa680324e5fb
parentMerge pull request #7 from benbjohnson/sorted-map-builder (diff)
parentAdd ListBuilder.Len() (diff)
downloadpds-549186e069824239fa3b0677b8b90cdfa2c21c48.tar.gz
pds-549186e069824239fa3b0677b8b90cdfa2c21c48.tar.xz
Merge pull request #8 from benbjohnson/list-builder-len
Add ListBuilder.Len()
-rw-r--r--immutable.go5
-rw-r--r--immutable_test.go4
2 files changed, 8 insertions, 1 deletions
diff --git a/immutable.go b/immutable.go
index e8fac90..c1a8aef 100644
--- a/immutable.go
+++ b/immutable.go
@@ -246,6 +246,11 @@ func (b *ListBuilder) List() *List {
return list
}
+// Len returns the number of elements in the underlying list.
+func (b *ListBuilder) Len() int {
+ return b.list.Len()
+}
+
// Get returns the value at the given index. Similar to slices, this method will
// panic if index is below zero or is greater than or equal to the list size.
func (b *ListBuilder) Get(index int) interface{} {
diff --git a/immutable_test.go b/immutable_test.go
index 9c3f548..c6dfc13 100644
--- a/immutable_test.go
+++ b/immutable_test.go
@@ -274,7 +274,9 @@ func (l *TList) Slice(start, end int) {
// Validate returns an error if the slice and List are different.
func (l *TList) Validate() error {
- if got, exp := len(l.std), l.im.Len(); got != exp {
+ if got, exp := l.im.Len(), len(l.std); got != exp {
+ return fmt.Errorf("Len()=%v, expected %d", got, exp)
+ } else if got, exp := l.builder.Len(), len(l.std); got != exp {
return fmt.Errorf("Len()=%v, expected %d", got, exp)
}