Skip to content

Commit

Permalink
v0.19.0
Browse files Browse the repository at this point in the history
  • Loading branch information
solsw committed Dec 1, 2021
1 parent e15f207 commit 7801d6f
Show file tree
Hide file tree
Showing 16 changed files with 3,116 additions and 0 deletions.
25 changes: 25 additions & 0 deletions dictionary.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//go:build go1.18

package go2linq

// Dictionary represents map[Key]Value.
type Dictionary[Key comparable, Value any] map[Key]Value

// GetEnumerator returns an enumerator that iterates through a Dictionary.
func (d Dictionary[Key, Value]) GetEnumerator() Enumerator[KeyValue[Key, Value]] {
r := make([]KeyValue[Key, Value], 0, len(d))
for k, v := range d {
r = append(r, KeyValue[Key, Value]{k, v})
}
return NewOnSlice(r...)
}

// AsDictionary converts a sequence of KeyValues to Dictionary.
func AsDictionary[Key comparable, Value any](en Enumerator[KeyValue[Key, Value]]) Dictionary[Key, Value] {
r := make(Dictionary[Key, Value])
for en.MoveNext() {
kv := en.Current()
r[kv.key] = kv.value
}
return r
}
Loading

0 comments on commit 7801d6f

Please sign in to comment.