diff --git a/CHANGELOG.md b/CHANGELOG.md index 8acd80e6..68c9aa7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ The format is based on [Keep a Changelog], and this project adheres to [Keep a Changelog]: https://keepachangelog.com/en/1.0.0/ [Semantic Versioning]: https://semver.org/spec/v2.0.0.html +## [Unreleased] + +### Added + +- Add `Len()` to `NameCollection` and `TypeCollection` interfaces + ## [0.7.1] - 2020-03-16 ### Added diff --git a/go.sum b/go.sum index a286fd0a..c7b70d54 100644 --- a/go.sum +++ b/go.sum @@ -7,8 +7,6 @@ github.com/dogmatiq/dogma v0.6.3 h1:owkM3lOFmLmwaFpYogO46taVuPJU5sF5YApICZr4ljk= github.com/dogmatiq/dogma v0.6.3/go.mod h1:8TdjQ5jjV2DcCPb/jjHPgSrqU66H6092yMEIF5HGx0g= github.com/dogmatiq/iago v0.4.0 h1:57nZqVT34IZxtCZEW/RFif7DNUEjMXgevfr/Mmd0N8I= github.com/dogmatiq/iago v0.4.0/go.mod h1:fishMWBtzYcjgis6d873VTv9kFm/wHYLOzOyO9ECBDc= -github.com/dogmatiq/linger v0.2.0 h1:WwpFy+0kwL0DNVFPx9tUuWxl2yZIALE5oFsjy8aWnKM= -github.com/dogmatiq/linger v0.2.0/go.mod h1:vQPEiGNtb3Qy+1IdmdSMyLxr4d9vPChknnQkClQimGM= github.com/dogmatiq/linger v0.2.1 h1:ecVwiFlTcQuQ7ygQXH5bUPkWNve8n5BmVnCYMGMQ3zc= github.com/dogmatiq/linger v0.2.1/go.mod h1:vQPEiGNtb3Qy+1IdmdSMyLxr4d9vPChknnQkClQimGM= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= diff --git a/message/name.go b/message/name.go index 53aeabe2..6e63fbea 100644 --- a/message/name.go +++ b/message/name.go @@ -16,6 +16,9 @@ type NameCollection interface { // HasM returns true if NameOf(m) is in the container. HasM(m dogma.Message) bool + // Len returns the number of names in the collection. + Len() int + // Range invokes fn once for each name in the container. // // Iteration stops when fn returns false or once fn has been invoked for all diff --git a/message/nameroles.go b/message/nameroles.go index ea13ba26..308f0563 100644 --- a/message/nameroles.go +++ b/message/nameroles.go @@ -77,6 +77,11 @@ func (nr NameRoles) IsEqual(o NameRoles) bool { return true } +// Len returns the number of names in the collection. +func (nr NameRoles) Len() int { + return len(nr) +} + // Range invokes fn once for each name in the container. // // Iteration stops when fn returns false or once fn has been invoked for all diff --git a/message/nameroles_test.go b/message/nameroles_test.go index cf8c917b..8fbf2c22 100644 --- a/message/nameroles_test.go +++ b/message/nameroles_test.go @@ -232,6 +232,17 @@ var _ = Describe("type NameRoles", func() { ) }) + Describe("func Len()", func() { + It("returns the number of names in the collection", func() { + nr := NameRoles{ + MessageATypeName: CommandRole, + MessageBTypeName: EventRole, + } + + Expect(nr.Len()).To(Equal(2)) + }) + }) + Describe("func Range()", func() { nr := NameRoles{ MessageATypeName: CommandRole, diff --git a/message/nameset.go b/message/nameset.go index f9ddac49..8a6364b1 100644 --- a/message/nameset.go +++ b/message/nameset.go @@ -164,6 +164,11 @@ func (s NameSet) IsEqual(o NameSet) bool { return true } +// Len returns the number of names in the collection. +func (s NameSet) Len() int { + return len(s) +} + // Range invokes fn once for each name in the container. // // Iteration stops when fn returns false or once fn has been invoked for all diff --git a/message/nameset_test.go b/message/nameset_test.go index ed05a3fa..43cbb2a4 100644 --- a/message/nameset_test.go +++ b/message/nameset_test.go @@ -313,6 +313,17 @@ var _ = Describe("type NameSet", func() { ) }) + Describe("func Len()", func() { + It("returns the number of names in the collection", func() { + s := NewNameSet( + MessageATypeName, + MessageBTypeName, + ) + + Expect(s.Len()).To(Equal(2)) + }) + }) + Describe("func Range()", func() { s := NewNameSet( MessageATypeName, diff --git a/message/type.go b/message/type.go index d67d2f6a..22048827 100644 --- a/message/type.go +++ b/message/type.go @@ -15,6 +15,9 @@ type TypeCollection interface { // HasM returns true if TypeOf(m) is in the container. HasM(m dogma.Message) bool + // Len returns the number of names in the collection. + Len() int + // Range invokes fn once for each type in the container. // // Iteration stops when fn returns false or once fn has been invoked for all diff --git a/message/typeroles.go b/message/typeroles.go index 46b691e7..7cd11b3d 100644 --- a/message/typeroles.go +++ b/message/typeroles.go @@ -77,6 +77,11 @@ func (tr TypeRoles) IsEqual(o TypeRoles) bool { return true } +// Len returns the number of types in the collection. +func (tr TypeRoles) Len() int { + return len(tr) +} + // Range invokes fn once for each type in the container. // // Iteration stops when fn returns false or once fn has been invoked for all diff --git a/message/typeroles_test.go b/message/typeroles_test.go index 0deb3876..0f67e9a3 100644 --- a/message/typeroles_test.go +++ b/message/typeroles_test.go @@ -232,6 +232,17 @@ var _ = Describe("type TypeRoles", func() { ) }) + Describe("func Len()", func() { + It("returns the number of types in the collection", func() { + tr := TypeRoles{ + MessageAType: CommandRole, + MessageBType: EventRole, + } + + Expect(tr.Len()).To(Equal(2)) + }) + }) + Describe("func Range()", func() { tr := TypeRoles{ MessageAType: CommandRole, diff --git a/message/typeset.go b/message/typeset.go index c53fbc15..120c4895 100644 --- a/message/typeset.go +++ b/message/typeset.go @@ -164,6 +164,11 @@ func (s TypeSet) IsEqual(o TypeSet) bool { return true } +// Len returns the number of types in the collection. +func (s TypeSet) Len() int { + return len(s) +} + // Range invokes fn once for each type in the container. // // Iteration stops when fn returns false or once fn has been invoked for all diff --git a/message/typeset_test.go b/message/typeset_test.go index 0e9021dd..c8a2ec27 100644 --- a/message/typeset_test.go +++ b/message/typeset_test.go @@ -313,6 +313,17 @@ var _ = Describe("type TypeSet", func() { ) }) + Describe("func Len()", func() { + It("returns the number of types in the collection", func() { + s := NewTypeSet( + MessageAType, + MessageBType, + ) + + Expect(s.Len()).To(Equal(2)) + }) + }) + Describe("func Range()", func() { s := NewTypeSet( MessageAType,