Last active
September 2, 2023 14:32
-
-
Save yurkimus/5b57e92d77f0403484091551c37e0736 to your computer and use it in GitHub Desktop.
Composing asynchronous functions with ramda
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
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