-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
3,116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.