Skip to content

Commit

Permalink
Add Len() method to [Type|Name]Collection.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Mar 25, 2020
1 parent 62282f5 commit bd6abfb
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
3 changes: 3 additions & 0 deletions message/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions message/nameroles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions message/nameroles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions message/nameset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions message/nameset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions message/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions message/typeroles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions message/typeroles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions message/typeset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions message/typeset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit bd6abfb

Please sign in to comment.