Nathan Bedell
07/27/2022, 1:48 AMnullable
effect using the new Effect API (rather than the now deprecated one?).
I am building what is essentially a modified version of nullable
, so an example of nullable
built with the new API would be very helpful.
From what I can tell, it looks like currently (at least on main) nullable
still uses the deprecated API.simon.vergauwen
07/27/2022, 6:25 AMEffect
, https://github.com/arrow-kt/arrow/blob/main/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/continuations/nullable.kt.simon.vergauwen
07/27/2022, 6:28 AMtypealias Null = Nothing?
context(EffectScope<Null>)
@OptIn(ExperimentalContracts::class)
public suspend fun <B> B?.bind(): B {
contract { returns() implies (this@bind != null) }
return this ?: shift(null)
}
suspend fun main() {
val example: String? = null
effect<Null, String> {
example.bind()
}.orNull()
}
Youssef Shoaib [MOD]
07/27/2022, 8:59 AMsimon.vergauwen
07/27/2022, 9:04 AMsimon.vergauwen
07/27/2022, 9:10 AMYoussef Shoaib [MOD]
07/27/2022, 9:33 AMsimon.vergauwen
07/27/2022, 9:40 AMstojan
07/27/2022, 11:25 AMThis file experiments with anI guess it's a typo, Validated and Eitherimplementation that exposes an API covering both Either and Either use-cases.Either
simon.vergauwen
07/27/2022, 11:47 AMsimon.vergauwen
07/27/2022, 11:48 AMNathan Bedell
07/27/2022, 11:47 PMNathan Bedell
07/27/2022, 11:48 PMNathan Bedell
07/27/2022, 11:52 PMsimon.vergauwen
07/28/2022, 7:18 AMSchedule
has a dependent type State
, but you don’t want to expose it from the Schedule<Input, Output>
type because it is only related to the internal impl of a Schedule
.
So you have to split the public type, and the “implementation type”. https://github.com/arrow-kt/arrow/blob/005c417fcad6831cf44503cfd35d3672d9b1302f/ar[…]oroutines/src/commonMain/kotlin/arrow/fx/coroutines/Schedule.kt
Then you can expose a synthetic constructor that allows for specifying the “dependent type” without exposing it from the Schedule<Input, Output>
type. https://github.com/arrow-kt/arrow/blob/005c417fcad6831cf44503cfd35d3672d9b1302f/ar[…]oroutines/src/commonMain/kotlin/arrow/fx/coroutines/Schedule.kt
It’s rather ugly, and I wouldn’t advise on using such patterns in Kotlin. The same can typically be achieved by leveraging different techniques, as done in the linked alternative encodings for Schedule
. Which results in much nicer, and simpler code.simon.vergauwen
07/28/2022, 7:18 AM