Skip to content

Instantly share code, notes, and snippets.

@yurkimus
Last active September 2, 2023 14:32
Show Gist options
  • Save yurkimus/5b57e92d77f0403484091551c37e0736 to your computer and use it in GitHub Desktop.
Save yurkimus/5b57e92d77f0403484091551c37e0736 to your computer and use it in GitHub Desktop.
Composing asynchronous functions with ramda
import { request, takeParsed } from 'base-fetch'
import { assoc, __, call, pipeWith, andThen } from 'ramda'
const result = { user: null, todo: null }
const getUser = (properties = result) =>
request('https://jsonplaceholder.typicode.com/users/1')
.then(takeParsed)
.then(assoc('user', __, properties))
const getTodo = (properties = result) =>
request('https://jsonplaceholder.typicode.com/todos/1')
.then(takeParsed)
.then(assoc('todo', __, properties))
call(pipeWith(andThen)([getUser, getTodo]))
.then(console.log) // logs { user: ..., todo: ... }
.catch(console.error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment