[Ramda] Convert a Promise.all Result to an Object with Ramda's zip and zipObj
zip to and with 39 object an
2023-09-14 09:00:52 时间
In this lesson, we'll use Promise.all
to get an array that contains the resolved values from multiple promises. Then we'll see how we can use Ramda to convert that array of values into a single object using zip
with fromPairs
. Then we'll refactor to use zipObj
.
const R = require('ramda'); const {fromPairs, zip, zipObj} = R; const getName = () => Promise.resolve('wan'); const getHobbies = () => new Promise((res, rej) => { "use strict"; setTimeout(() => res(['basketball', 'skiing'])); }); Promise.all([getName(), getHobbies()]) // .then(console.log); // [ 'wan', [ 'basketball', 'skiing' ] ] // Make it as object style Promise.all([getName(), getHobbies()]) .then(([name, hobbies]) => ({name, hobbies})) // .then(console.log); // { name: 'wan', hobbies: [ 'basketball', 'skiing' ] } // Using zip & fromPairs Promise.all([getName(), getHobbies()]) .then(zip(['name', 'hobbies'])) // [ [ 'name', 'wan' ], [ 'hobbies', [ 'basketball', 'skiing' ] ] ] .then(fromPairs) // { name: 'wan', hobbies: [ 'basketball', 'skiing' ] } // .then(console.log); // zipOjb == zip + fromPairs Promise.all([getName(), getHobbies()]) .then(zipObj(['name', 'hobbies'])) .then(console.log) // { name: 'wan', hobbies: [ 'basketball', 'skiing' ] }
相关文章
- LINUX 命令 之 zip 解压缩
- 【说站】python zip_longest和zip的比较
- linux中rar解压命令_tar解压zip文件
- 【愚公系列】2023年06月 网络安全(交通银行杯)-zip伪加密
- Linux中zip压缩和unzip解压缩命令详解程序员
- Java实现Zip压缩目录中的所有文件详解编程语言
- Linux下增加Zip文件的实现方法(linux给zip加文件)
- Zip加密Linux——安全保护你的数据(zip加密linux)
- 安装Zip版MySQL: 走上正确的路(安装zip版mysql)
- 快速上手:Linux下zip压缩命令(linux压缩命令zip)
- Linux安装Zip包的简单步骤(linux安装zip包)
- 函数解密Oracle ZIP函数的神秘功效(oraclezip)
- Linux 下载解压 ZIP 文件的方法(zip解压linux)
- Zip 压缩在 Linux 中的应用(zip压缩linux)
- Linux解压ZIP文件到指定文件夹的操作方法(linux解压zip到指定文件夹)
- MySQL的ZIP配置简单易学(mysql zip 配置)
- 如何在MySQL中使用zip解压文件(mysql zip解压后)
- MySQL zip版安装详解(mysql zip版安装)
- MySQL压缩包(32位)下载指南(mysql zip 32)
- MySQL下载ZIP包,解压安装教程(mysql下载的是zip)
- c#使用DotNetZip封装类操作zip文件(创建/读取/更新)实例
- 通过javaapi实现解压缩zip示例
- php调用nginx的mod_zip模块打包ZIP文件