Created
January 26, 2017 16:31
-
-
Save djleonskennedy/4bf580c41b104bec1111ac4beb4aaeca to your computer and use it in GitHub Desktop.
futurizeP get payload with json()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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