mirror of
https://github.com/aditya-K2/gspt.git
synced 2026-01-09 22:08:04 -05:00
Implement Map Function
This commit is contained in:
@@ -131,3 +131,10 @@ func artistName(s []spotify.SimpleArtist) string {
|
|||||||
func wrap(args ...interface{}) []interface{} {
|
func wrap(args ...interface{}) []interface{} {
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Map[K any, V any](a []K, f func(K) V) (res []V) {
|
||||||
|
for _, v := range a {
|
||||||
|
res = append(res, f(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@@ -65,12 +65,10 @@ func (a *AlbumView) AddToPlaylist() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *AlbumView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
|
func (a *AlbumView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
|
||||||
tracks := make([]spotify.ID, 0)
|
addToPlaylist(Map((*(*a.currentFullAlbum).Tracks)[start:end+1],
|
||||||
sTracks := (*(*a.currentFullAlbum).Tracks)
|
func(s spotify.SimpleTrack) spotify.ID {
|
||||||
for k := start; k <= end; k++ {
|
return s.ID
|
||||||
tracks = append(tracks, sTracks[k].ID)
|
}))
|
||||||
}
|
|
||||||
addToPlaylist(tracks)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,11 +53,10 @@ func (l *LikedSongsView) AddToPlaylist() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *LikedSongsView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
|
func (l *LikedSongsView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
|
||||||
tracks := make([]spotify.ID, 0)
|
addToPlaylist(Map((*l.likedSongs)[start:end+1],
|
||||||
for k := start; k <= end; k++ {
|
func(s spotify.SavedTrack) spotify.ID {
|
||||||
tracks = append(tracks, (*l.likedSongs)[k].ID)
|
return s.ID
|
||||||
}
|
}))
|
||||||
addToPlaylist(tracks)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,12 +63,10 @@ func (p *PlaylistView) AddToPlaylist() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *PlaylistView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
|
func (p *PlaylistView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
|
||||||
tracks := make([]spotify.ID, 0)
|
addToPlaylist(Map((*(*p.currentUserFullPlaylist).Tracks)[start:end+1],
|
||||||
sTracks := (*(*p.currentUserFullPlaylist).Tracks)
|
func(s spotify.PlaylistTrack) spotify.ID {
|
||||||
for k := start; k <= end; k++ {
|
return s.Track.ID
|
||||||
tracks = append(tracks, sTracks[k].Track.ID)
|
}))
|
||||||
}
|
|
||||||
addToPlaylist(tracks)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,11 +42,10 @@ func (r *RecentlyPlayedView) AddToPlaylist() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *RecentlyPlayedView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
|
func (r *RecentlyPlayedView) AddToPlaylistVisual(start, end int, e *tcell.EventKey) *tcell.EventKey {
|
||||||
tracks := make([]spotify.ID, 0)
|
addToPlaylist(Map(r.recentlyPlayed[start:end+1],
|
||||||
for k := start; k <= end; k++ {
|
func(r spotify.RecentlyPlayedItem) spotify.ID {
|
||||||
tracks = append(tracks, r.recentlyPlayed[k].Track.ID)
|
return r.Track.ID
|
||||||
}
|
}))
|
||||||
addToPlaylist(tracks)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user