origamitower / folktale

[not actively maintained!] A standard library for functional programming in JavaScript
https://folktale.origamitower.com/
MIT License
2.05k stars 102 forks source link

Convert Promise-returning functions to Task-returning functions #97

Closed robotlolita closed 7 years ago

robotlolita commented 7 years ago

Folktale should support converting from Promises to a more usable type. Because Promises are already eventual values, it makes sense to convert the functions that create them to functions creating Tasks instead of converting actual Promises to Tasks.

In essence, a function yielding a Promise, like:

f :: (Any...) => Promise Error Any

Would become a function yielding a Task, like:

promiseFunctionToTask(f) :: (Any...) => Task Error Any

promiseFunctionToTask is a really long name, though, so if you have better naming suggestions feel free to discuss them here :)

Where this goes?

In the data/conversions module, as promiseFunctionToTask. In the data/task module, as fromPromiseFunction.

Refer to existing data/conversions modules, and the from* functions in data/maybe and data/either to see more or less how this is done.