-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
function ideas #184
Comments
const res = await asyncUnfoldExclusive(x=>Promise.resolve(x+1), x => x<6, 2)
console.log(res) // [3,4,5] |
@richytong yo! in fp-ts we can generalize computation by Either monad. for example: pipe(
E.right(1),
E.map((val) => 1), // output: 1
E.mapLeft(() => 'err value')), // not achievable in this case
) and this is good way for handling errors and ellegant break computation, but its about special data structure. in rubico i have when/unless/switchCase and raw structure without error signs (tags). and my code without either structure start expand with additional logic. @richytong what you think about controlling flow in rubico and either monad in fp? maybe you can highlight solutions for this cases. thanks! |
@kalagin Either monad is not a replacement for alternation, it is only a replacement for error handling with imperative try/catch syntax. rubico's To your example: // rubico
tryCatch(1, val => 1, () => 'err value')
// fp-ts
pipe(
E.right(1),
E.map((val) => 1), // output: 1
E.mapLeft(() => 'err value')), // not achievable in this case
) A toy http handler with tryCatch const myHandler = (request, response) => tryCatch(request, pipe([
request => parseRequestBody(request),
data => myDb.get(data.userId),
user => {
response.end(JSON.stringify(user))
},
]), error => {
console.error(error)
response.end(error.message)
}) |
The text was updated successfully, but these errors were encountered: