0

Defining an IO Context in Kotlin

 1 year ago
source link: https://www.youtube.com/watch?v=l0mCgHhFkP4
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

24 Comments

Sort by
Add a comment...
The `magic` function you created is what I've been calling `given()`. It reads nicely like "summon me the given object of type C here please". I think also you could've just wrote `this@IO` since that is one way of referring to context receivers. That naming is inspired by Arrow-meta's type proofs plugin that used the same name for it magical summoning function.

Read more

Refactoring to Kotlin with Duncan McGregor
·
I think JUnit has some capability of providing a parameter value, no? If it does, you can use that and mark your tests as `context(IO)` because context receivers compile down to just parameters. A different way of achieving that is to mark your test class with `context(IO)` and provide a default constructor that provides that IO context
null
·

You could make `retryingPricing` marked with `context(IO)` but you'll have to change it to a computed property like this:

`context(IO) private val retryingPricing get() = retry(..., { pricing(magic(), it) } )` And `magic` will actually get its context from the context of whoever calls the `retryingPricing` property, thus there'd be no need to change the signature of `retry`

Read more

null
·
Very cool, reminds me of Haskell.
null
·

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK