Skip to content

Commit

Permalink
args,meta: add a Len()
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMure committed Dec 12, 2024
1 parent 042d6dc commit 416345d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ func (a *Args) Include(other Iterator) {
}
}

// Len return the number of arguments.
func (a *Args) Len() int {
return len(a.Keys)
}

// Iter iterates over the args key/values
func (a *Args) Iter() iter.Seq2[string, ipld.Node] {
return func(yield func(string, ipld.Node) bool) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/args/readonly.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ func (r ReadOnly) GetNode(key string) (ipld.Node, error) {
return r.args.GetNode(key)
}

func (r ReadOnly) Len() int {
return r.args.Len()
}

func (r ReadOnly) Iter() iter.Seq2[string, ipld.Node] {
return r.args.Iter()
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ func (m *Meta) Include(other Iterator) {
}
}

// Len returns the number of key/values.
func (m *Meta) Len() int {
return len(m.Values)
}

// Iter iterates over the meta key/values
func (m *Meta) Iter() iter.Seq2[string, ipld.Node] {
return func(yield func(string, ipld.Node) bool) {
Expand Down
4 changes: 4 additions & 0 deletions pkg/meta/readonly.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func (r ReadOnly) GetNode(key string) (ipld.Node, error) {
return r.meta.GetNode(key)
}

func (r ReadOnly) Len() int {
return r.meta.Len()
}

func (r ReadOnly) Iter() iter.Seq2[string, ipld.Node] {
return r.meta.Iter()
}
Expand Down

0 comments on commit 416345d

Please sign in to comment.