Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Len() method to [Type|Name]Collection. #69

Merged
merged 1 commit into from
Mar 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add Len() method to [Type|Name]Collection.
jmalloc committed Mar 25, 2020
commit bd6abfba0797e2bf94b1dbfc15058436148eedc9
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
3 changes: 3 additions & 0 deletions message/name.go
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions message/nameroles.go
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions message/nameroles_test.go
Original file line number Diff line number Diff line change
@@ -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,
5 changes: 5 additions & 0 deletions message/nameset.go
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions message/nameset_test.go
Original file line number Diff line number Diff line change
@@ -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,
3 changes: 3 additions & 0 deletions message/type.go
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions message/typeroles.go
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions message/typeroles_test.go
Original file line number Diff line number Diff line change
@@ -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,
5 changes: 5 additions & 0 deletions message/typeset.go
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions message/typeset_test.go
Original file line number Diff line number Diff line change
@@ -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,