jucardi / go-streams

Stream Collections for Go. Inspired in Java 8 Streams and .NET Linq
MIT License
308 stars 23 forks source link

Is it possible to obtain a map as an output of stream operations? #2

Closed seanrmurphy closed 3 years ago

seanrmurphy commented 4 years ago

Is seems straightforward to obain an array as an output of stream operations (using ToArray()). Is it also possible to obtain a map?

jucardi commented 4 years ago

@seanrmurphy sorry for the late response, right now you can't obtain a map, you can however obtain a KeyValuePair list which you could convert into a map

source := map[string]string{
// . . .  Some data here in the map
}

target := map[string]string{}

streams.From(b). {some operations here} .ForEach(func (i interface{} {
    x := i.(streams.KeyValuePair)
    target[x.Key.(string)] = x.Value(string)
})