iniyanp
7/7/2017 - 12:36 AM

Use of Kleisli

Use of Kleisli

Hi Cody,

[5:10] 
Just trying to understand the usage of Kleisli. Kleisli[Task, A, Unit] means given A it would give us Task[Unit]. It s a syntactic sugar for this function `A => Task[Unit]` ?
I see lot of places in gazelle as well as in DVR, mainly the context is A. and the context has accountId, transactionId.. etc. so when we create a service, if all our operations takes some common parameter (let s say accountId), then is it good to model as a Kleisli. ? so that given the common parameter , it would give us Task[Unit] . Is that my understanding correct? Trying to understand in what circumstances I should use Kleisli. Thanks :slightly_smiling_face:

cody
[5:32 PM] 
hi, Iniyan. Your understanding is exactly correct

[5:33] 
So in some places you’ll see people write services where basically all of the methods take an implicit `Config` parameter

[5:33] 
so that you don’t have to explicitly pass in the config to every method

[5:33] 
using `Kleisli` is an alternate. You just put everything into a for-comprehension instead of passing around an implicit `Config`

[5:34] 
I think that there are pros and cons of using it. In some cases it makes things a lot neater and in other cases just passing around a parameter seems like it’s simpler

iniyan [5:34 PM] 
implicit vs Kleisli. Amazing comparison. :slightly_smiling_face: I understand better now. Thanks Cody :slightly_smiling_face: