I'd like to see EitherAsync, MaybeAsync and etc
import { left, right, type EitherAsync } from "@sweet-monads/either";
import { just, none, type Maybe } from "@sweet-monads/maybe";
import type { Order } from "../types/order";
import type { RetailCRM_Config } from "../request";
import { NetworkError } from "$lib/core/errors/NetworkError";
export async function getOrder(
config: RetailCRM_Config,
id: number
): EitherAsync<NetworkError, Maybe<Order>> {
instead of:
import { left, right, type EitherAsync } from "@sweet-monads/either";
import { just, none, type Maybe } from "@sweet-monads/maybe";
import type { Order } from "../types/order";
import type { RetailCRM_Config } from "../request";
import { NetworkError } from "$lib/core/errors/NetworkError";
export async function getOrder(
config: RetailCRM_Config,
id: number
): Promise<Either<NetworkError, Maybe<Order>>> {
importance: make my life easier
At the moment I do it this way: app.d.ts:
declare module "@sweet-monads/either" {
type EitherAsync<L, R> = Promise<import("@sweet-monads/either").Either<L, R>>;
}
I love your library. Thank you!
Hi @wennerryle. Thank you so much for your feedback; I'm thrilled to hear it ❤️ May I ask you just a little bit to clarify the issue? Would you like to see such aliases for each type or some additional API? What kind of API is missing if the answer is also an API?
Thank you for response :) Yep, you're correct, I'd like to see such aliases for each type
@JSMonk I like your library, however chaining promises handling with Either.chain still looks not very convenient. In purify-ts or purifree-ts they have a class EitherAsync which allows to handle promises in pretty elegant way
const result = EitherAsync.fromPromise(api.getUsers)
.map(response => response.users)
.map(sortAndFilterUsers)
.run()
Would you consider this useful to implement?
@AndrewGapon, from the API perspective, it looks good. However, I'm not sure there will be no de-optimizations from the VM sides when using thenable objects instead of the regular Promise. https://github.com/v8/promise-performance-tests