DEV Community

Discussion on: Then After forEach

Collapse
 
joelnet profile image
JavaScript Joel

With MojiScript I have created an async map, filter and reduce to make things like this cake.

import map from 'mojiscript/list/map'

const sleep = timeout => new Promise(resolve => setTimeout(resolve, timeout))

const array = [ 1, 2, 3 ]

const asyncTransform = async x => {
  await sleep(1000)
  return x * 2
}

map (asyncTransform) (array) //=> Promise ([ 2, 4, 6 ])

Check it out here: mojiscript.js.org/#/list-map

Also related: Why async code is so damn confusing (and a how to make it easy)