rryam / MusadoraKit

The ultimate companion to MusicKit.
http://exploringmusickit.com
MIT License
344 stars 22 forks source link

Refactor MusicHistoryRequest and MusicRecommendationRequest to have albums, stations and playlists as properties #2

Closed rudrankriyam closed 2 years ago

rudrankriyam commented 2 years ago

With the current implementation, it feels confusing to use and get an array of albums from the items:

var recentlyPlayedAlbums: [Album] = []

let request = MusicHistoryRequest(for: .recentlyPlayed)
let response = try await request.response()

recentlyPlayedAlbums = response.items.compactMap { item in 
    switch item {
        case .album(let album): return album
        default: return nil
    }
}

It would be nice if you could directly fetch the items:

var recentlyPlayedAlbums: Albums?

let request = MusicHistoryRequest(for: .recentlyPlayed)
let response = try await request.response()

recentlyPlayedAlbums = response.albums