Skip to content

Instantly share code, notes, and snippets.

@ivancorrales
Created January 13, 2019 18:29
Show Gist options
  • Save ivancorrales/6ff38c699f109f5df510083c93442cf6 to your computer and use it in GitHub Desktop.
Save ivancorrales/6ff38c699f109f5df510083c93442cf6 to your computer and use it in GitHub Desktop.
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