DenisFrezzato / hyper-ts

Type safe middleware architecture for HTTP servers
https://denisfrezzato.github.io/hyper-ts/
MIT License
391 stars 18 forks source link

Usage with TaskEither or ReaderTaskEither #13

Closed wmaurer closed 5 years ago

wmaurer commented 5 years ago

A complete n00b question, here as I am really struggling and I can't find any usage of hyper-ts in 'real life'.

Is it possible to use MiddlewareTask with TaskEither or ReaderTaskEither? Or would I have to define a MiddlewareTaskEither? (which I think is beyond my current capability).

Thanks for any help.

EDIT: fixed spelling TaskReader -> TaskEither

mlegenhausen commented 5 years ago

@wmaurer I think you mean TaskEither?

Yes you can for example you can lift any TaskEither value by using

// lift from MiddlewareTask
lift<StatusOpen, Either<Error, string>>(someTaskEither.value);

or if you want access the Conn you can use

new MiddlewareTask(c => myRetuningTaskEitherFn(c).value.map(r => tuple(r, c)))

your last question about MiddlewareTaskEither would be very interesting. @gcanti do you have any thoughts about it? Would it be possible? Would it need something like an ifold function?

gcanti commented 5 years ago

@mlegenhausen Yeah, theoretically it would be possible. It would mean to define MonadMiddleware4, InducedMonad4, IxMonad4 etc... and then a MonadMiddleware4 instance for TaskEither

gcanti commented 5 years ago

@mlegenhausen I'm thinking of simplify the architecture and drop tagless final in favour of a single concrete instance, likely a ReaderTaskEither instance. What do you think?

mlegenhausen commented 5 years ago

@gcanti I have never used the tagless feature at all. Testing is already easy with the concrete instances. TaskEither should be minimum, cause of the great error handing capabilities. How would the environment of the Reader part look like?

Nice to hear that hyper-ts will be developed further. Its currently my default framework for middleware development. Do you plan other features?

gcanti commented 5 years ago

Testing is already easy with the concrete instances

Yeah, that's what I thought as well.

How would the environment of the Reader part look like?

I am torn between TaskEither and ReaderTaskEither.

Let's start from TaskEither, I'll send a PR based on https://github.com/gcanti/hyper-ts/pull/14 so we can discuss an actual implementation.

sledorze commented 5 years ago

readertaskeither would help a lot structuring dependencies. (the zio way) However, stacking the transformers has a cost..