我有以下示例代码来获取 uuid:
const Result = require('folktale/result')
const Future = require('fluture')
Future.prototype.flatMap = Future.prototype.chain
const fetch = Future.encaseP(require('node-fetch'))
const message = err => `ERROR: ${err.message}`
function getUuid () {
return fetch('https://httpbin.org/uuid')
}
const future = getUuid()
.map(response => {
const responseJson = response.json.bind(response)
const getResponseBody = Future.encaseP(responseJson)
return getResponseBody()
})
.map(obj => obj.uuid)
const result = future.fold(Result.Error, Result.Ok).fork(x => x, x => x)
console.log(result) // [Function: Sequence$cancel]
result.map(
x => {
return message(x)
},
x => {
console.log(x)
return x
}
)
结果不是可映射类型,并在我调用时引发错误result.map
:
TypeError: result.map is not a function