Skip to content

Instantly share code, notes, and snippets.

@djleonskennedy
Created January 26, 2017 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djleonskennedy/4bf580c41b104bec1111ac4beb4aaeca to your computer and use it in GitHub Desktop.
Save djleonskennedy/4bf580c41b104bec1111ac4beb4aaeca to your computer and use it in GitHub Desktop.
futurizeP get payload with json()
const Task = require('data.task');
const fetch = require('node-fetch');
// futurizeP :: (* -> Promise a b) -> * -> Task a b
const futurizeP = require('futurize').futurizeP(Task);
// fetchJson_ :: Url -> Promise Error Object
const fetchJson_ = url => fetch(url).then(res => res.json());
// fetchJson :: Url -> Task Error Object
const fetchJson = futurizeP(fetchJson_);
// getUser :: Url -> UserId -> Task Error Object
const getUser = apiUrl => Id => fetchJson(`${apiUrl}/${Id}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment