Skip to content

Aff and the correct way to do async/await pattern functionally. #1111

Answered by louthy
EivindAntonsen asked this question in Q&A
Discussion options

You must be logged in to vote

Because I don't know the library you're using, I've created this mock of it:

namespace SpotifyAPI
{
    public record Track(string Artist, string Title);
    public record Playlist(string Name, Track[] Tracks);
    
    public static class SpotifyHttpClient
    {
        public static Task<Playlist[]> GetUserPlaylistsAsync(string userId) => 
            default;
    }
}

For the simplest version of Aff (the non-runtime version), you can do this:

namespace SpotifyAff
{
    public static class Spotify
    {
        public static Aff<Seq<Playlist>> getUserPlaylist(string userId) =>
            Aff(async () => 
                Seq(await SpotifyAPI.SpotifyHttpClient

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
2 replies
@EivindAntonsen
Comment options

@louthy
Comment options

Answer selected by EivindAntonsen
Comment options

You must be logged in to vote
2 replies
@evermanwa
Comment options

@EivindAntonsen
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants