JSMonk / sweet-monads

The library which provides useful monads, interfaces, and lazy iterators.
MIT License
343 stars 22 forks source link

feat: Implement 'fromTry' for 'Either' #53

Closed wookieb closed 1 year ago

wookieb commented 1 year ago

Related to #48

Lonli-Lokli commented 1 year ago

Hi!

I would like to ask why do we have Either<L,R> and not Either<unknown, R> ? Errors are not strongly typed in Js

EDIT1. Also, with this sample from README

const a1 = fromTry(() => 2); // Either<never, number>.Right
    const a2 = fromTry(() => {
      throw new Error("test");
    }); // Either<Error, never>.Left

a1 has type Either<unknown, number> a2 has type Either<unknown, never>

EDIT2 Same for fromPromise actually, and also Returns Right with the promise value if the provided promise fulfilled or Left with the error value if the provided promise rejected. I think it's incorrect as it will return Promise of Right or Left, not the Right\Left itself

wookieb commented 1 year ago

@Lonli-Lokli You're obviously right! Fixed in another branch. Both addressed in #59