Skip to content

Instantly share code, notes, and snippets.

@BrantApps
Last active November 19, 2019 02:17
Show Gist options
  • Select an option

  • Save BrantApps/f56bf5a4118cce3d280720f9e7a4171f to your computer and use it in GitHub Desktop.

Select an option

Save BrantApps/f56bf5a4118cce3d280720f9e7a4171f to your computer and use it in GitHub Desktop.
Using fp-ts to iterate through a list of promises transforming them to a sequence then extracting the ids
import {pipe} from "fp-ts/lib/pipeable"
import * as A from "fp-ts/lib/Array"
import * as T from "fp-ts/lib/Task"
const ids = await pipe(
someListings,
A.map(listing => {
return () => persistence.createListing(listing)
}),
A.array.sequence(T.task),
T.map(listings => listings.map(listing => listing.id)),
)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment