Flattening K<M, Fin<T>> where M : Fallible<M> #1424
-
Hi there, I'm adapting the code in the Newsletter sample to create a Cosmos DB client wrapper to get a better feel for the new HKTs in v5 (which are awesome - thank you!) and I'm trying to adapt the following code, which works with an
To work with a
Here is the (non-compiling) code I'm working with:
What I want to do is something like Would someone be able to point me in the right direction? Maybe I'm going about this the wrong way - I am quite new to all of this. Thank you so much for your time! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
But, because public static K<M, string> sendGridApiKey =>
from k in configIO.Map(t => t.SendGridApiKey)
from _ in when(k.IsFail, error<M>((Error)k)
select (string)k; There's potentially a way to do a natural-transformation between By the way, I'd be slightly wary of going all in with the However, having said that, for reusable library components, like database access, it does give complete abstraction and allows the lifting into other monadic types. So there is that! YMMV of course. |
Beta Was this translation helpful? Give feedback.
Flatten
is monadic, not fallible, so there's no automatic way of flattening two different monad-types.But, because
Fin
supports explicit casts toError
(and thewhen
predicate has already tested that theFin
is in aFail
state), you should be able to just cast thek
toError
There's potentially a way to do a natural-transformation between
K<Fin, A> -> K<M, A>
whenM
isFallible
, but right now none of the interfaces support that (although I am adding natural-transformations soon).By the way, I'd be slightly wary of going all …