Created
January 13, 2019 18:29
-
-
Save ivancorrales/6ff38c699f109f5df510083c93442cf6 to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"fmt" | |
"github.com/wesovilabs/koazee" | |
"koazee-examples-v2/model" | |
) | |
// Print the albums sorted by the number of tracks | |
type AlbumTracks struct { | |
Title string | |
Tracks int | |
} | |
func main() { | |
fmt.Println("Print the albums sorted by the number of tracks:") | |
koazee.StreamOf(model.Albums). | |
Map(func(a *model.Album) *AlbumTracks { | |
return &AlbumTracks{a.Title, len(a.Songs)} | |
}).Sort(func(first, second *AlbumTracks) int { | |
if first.Tracks > second.Tracks { | |
return -1 | |
} | |
return 1 | |
}).ForEach(func(a *AlbumTracks) { | |
fmt.Printf("- '%s' has %d tracks\n", a.Title, a.Tracks) | |
}).Do() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment