Better asynchrony Support #47
Replies: 2 comments 4 replies
-
|
Hello, how's it going? I was thinking about trying to support the interoperability of it.each([
{
type: 'Right',
either: Either.right(2),
syncClosure: (x: number) => x * 2,
asyncClosure: async (x: number) => x * 2,
expected: 8,
},
])(
'$type should handle map with another async map operation correctly',
async ({ either, syncClosure, asyncClosure, expected }) => {
either
.map(syncClosure)
.toPromise()
.map(asyncClosure)
.complete(
async (value) => expect(await value).toEqual(expected),
async (error) => expect(error).toBeUndefined()
);
}
);Where in abstract class we add: // abstract class Either<L, R>
abstract toPromise(): Future<R | L>;And in its implementations: // class Left<L, R>
toPromise(): Future<L> {
return Future.of(() => Promise.resolve(this.value));
}// class Right<L, R>
toPromise(): Future<R> {
return Future.of(() => Promise.resolve(this.value));
}I'm no expert in this field, but I find it interesting to be able to chain synchrony with asynchrony, giving the latter the possibility to have previous asynchronous calls. Let me know if you have any feedback. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @Wolfremium13! Thanks for your proposal! :D The approach is interesting. To keep something like the pipeline of transformations you propose is something that we want to. The usage of
What do you think @myugen? This proposal allows creating a pipeline of transformation with sync and async stuff, for me the main requirement. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The current version (v1.1.0) of the library supports Asynchrony but it needs another level of wrapping: Promise<Monad<value|description>>
On the other hand, some operations cannot be performed (map or flatmap) as sync processes.
We are thinking some approaches to improve this. But you can contribute with your ideas :D
Our main constrain is not breaking any contract, and we would like something easy to understand
Beta Was this translation helpful? Give feedback.
All reactions