I have the following sample code to fetch a 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
}
)
The result is not a mappable type and throws an error when I invoke result.map
:
TypeError: result.map is not a function
fork
executes future and expects that you handle results in callbacks you've provided infork
arguments, and more importantly returnscancel
function, not nextFuture
as you expect my applying.map
on its result.Change the code to: