gcanti / logging-ts

Composable loggers for TypeScript
https://gcanti.github.io/logging-ts/
MIT License
98 stars 8 forks source link

Upgrade to fp-ts 2.0 #9

Closed mstn closed 4 years ago

mstn commented 5 years ago

It upgrades fp-ts to 2.0. Related to #8.

I defined a logger with an interface

interface Logger<M, A> {
  (a: A): HKT<M, void>
}

The problem is that HKT<M, void> is a "phantom" type and any Logger implementation returns a Kind<M, void> instead, resulting in a type error.

My solution is a logger "constructor" that "attaches" (virtually) _URI and and _A to a simple Kind<M, void> object.

const getLogger = <M extends URIS, A>(l: (a: A) => Kind<M, void>) => l as (a: A) => Kind<M, void> & { _URI: M, _A: void }

It is the first time I play with fp-ts HKTs, so I do not know if there is a better way. What do you think, @gcanti?

TODO

gcanti commented 4 years ago

@mstn sorry for being so late, there's a draft in the 0.3.0 branch

jfhbrook commented 4 years ago

@gcanti what's blocking you from releasing 0.3.0 ? I'm extremely bad at higher order typing stuff but am an old hand at javascript w/ some scala experience if there's a way I can reasonably help.

jfhbrook commented 4 years ago

(loving fp-ts by the way, it's making me super nostalgic for scalaz - in a good way!)

gcanti commented 4 years ago

what's blocking you from releasing 0.3.0 ?

@jfhbrook well nothing, my draft is 22 hours old though, and it's quite different from @mstn 's solution.

@mstn basically I used the same technique used in OptionT, EitherT, ReaderT, etc... so index.ts works like a LoggerT and LoggerIO is a logger specialized to IO computations

jfhbrook commented 4 years ago

Oh wow, didn't even notice the timestamps - just thought you coincidentally replied to an issue around the same time I was digging into it. Stoked to see you're on it! And yeah, if you need a test drive or anything I'm in general trying to hack on typescript on weekends, just lmk,.

mstn commented 4 years ago

@gcanti thanks, Your solution looks better than mine :) Feel free to close this pr if you feel like it

gcanti commented 4 years ago

Closing in favor of https://github.com/gcanti/logging-ts/pull/17

@mstn thanks for reviewing