Luke
06/22/2022, 2:50 PMval getId: (MyClass) -> String? = MyClass.somePath.id::getOrNull
, which works, but I would prefer to call a method instead of ::getOrNull
to return a lambda directly so I don't have to explicit the variable type.Erik Dreyer
06/22/2022, 8:37 PMflatMap
like operation with two methods that produce ValidatedNel<E,A>
where the “right” side of the first method is an input into the second method?Moritz Lindner
06/23/2022, 12:47 PMeither.eager
-For-Comprehensions. Do you have any tips regarding debugging? It can get quite cumbersome sometimes because of the actual execution in either.eager?
Regards 🙂Nathan Bedell
06/23/2022, 3:18 PMOllis
06/24/2022, 5:57 PMPartho Paul
06/25/2022, 2:32 PMfun InputRequest.validate(): Validated<IncorrectInput, InputRequest> =
userType.validateMail(obj.inputEnum)
.zip(username.validateUserName(), obj.validateObj()) {
userType,
userName,
obj ->
InputRequest(userType, userName, obj)
}
.mapLeft(::IncorrectInput)
fun String.validateUserType(enum: Enum):ValidatedNel<InvalidUserType, String> {
val trimmed = trim()
if(trimmed.isBlank()) {
return "User type can't be empty".invalidNel().mapLeft(toInvalidField(::InvalidUserType))
}
if(trimmed == "other" && !(enum == Enum.E1 || enum == Enum.E2)) {
return "Given user type is not supported with E1 and E2".invalidNel().mapLeft(toInvalidField(::InvalidMail))
}
return validNel()
}
In the above code, validateUserType
looks a bit dirty to me. Is there a better to do the same?Gopal S Akshintala
06/27/2022, 2:09 PMLukasz Kalnik
06/30/2022, 9:21 AMEither
but with more subtypes?
I need something like this:
sealed class DataState<T> {
class Loading<T> : DataState<T>()
data class Error<T>(val error: CallError) : DataState<T>()
data class DataLoaded<T>(
val data: T
) : DataState<T>()
}
And I want only the DataLoaded
subtype to behave as Either.Right
(e.g. when using flatMap()
) and all other subtypes behave as Either.Left
, i.e. having early returns from flatMap()
.
I especially would like to have the monad comprehension syntax analogous to the either {}
DSL (using .bind()
).Lukasz Kalnik
06/30/2022, 12:32 PMeither {}
monad comprehension also outside suspending context? I want to use it in a non-suspending function, but it seems that arrow.core.continuations.either
only has a suspending version of `invoke()`:
public suspend operator fun <E, A> invoke(f: suspend EffectScope<E>.() -> A): Either<E, A> =
effect(f).toEither()
Lukasz Kalnik
07/01/2022, 3:11 PM!= null
Apart from the standard syntax:
myVal1 != null || myVal2 != null || myVal3 != null
This is ok, but I would like to write something more expressive, like:
listOf(myVal1, myVal2, myVal3).anyNotNull()
Lukasz Kalnik
07/04/2022, 8:50 AMbind()
on the Either
contained in the `MutableStateFlow`'s value
here cannot be resolved. commonConnectorApi.renameControlDevice()
returns Either<CallError, Unit>
.thanh
07/04/2022, 10:21 AMpublic fun <A, B, C> Either<A, B>.combine(SGA: Semigroup<A>, b: Either<A, C>): Either<A, Pair<B, C>>
Lukasz Kalnik
07/08/2022, 2:20 PMplugins {
id("com.google.devtools.ksp")
}
dependencies {
implementation("io.arrow-kt:arrow-optics:$arrowVersion")
ksp("io.arrow-kt:arrow-optics-ksp-plugin:$arrowVersion")
}
I have also annotated my data classes:
@optics
data class ConnectorWithSensors(
val connector: Connector,
val sensors: List<ItemSelection>,
) {
companion object
}
@optics
data class ItemSelection(
val id: String,
val selected: Boolean,
) : {
companion object
}
However I cannot access the extensions generated on companion object like ConnectorWithSensors.sensors
.Charlie Christensen
07/08/2022, 2:27 PMparZip
inside of an either
block.
suspend fun refresh(): Either<Throwable, Unit> = either {
parZip(
{ refreshA().bind() },
{ refreshB().bind() }
) { dataA, dataB ->
persistData(dataA, dataB).bind()
}
}
But if one of the suspending functions doesnt return the proper type, the exception is not caught.
The crash happens with an unsafe cast at line 85 of ParZip.kt
f(a as A, b as B)
Is there any way to catch this exception? I feel like I would need to double wrap the EitherYoussef Shoaib [MOD]
07/10/2022, 3:25 PMOption
encoding in Arrow using `value class`es? If there isn't anything proposed right now, I think I might've come up with one that instead of one None
object it uses a None(Int)
class that indicates the level of nesting of the Option
(sort of similar to the Failure
class used in Result
).
If there hasn't been any successful experiments for a nested Option
, I could make a PR in the next hour or so for one, if the arrow team sees that it is fit for the library.Slackbot
07/11/2022, 7:22 AMDirk
07/11/2022, 9:04 AMTower Guidev2
07/11/2022, 11:05 AMio.arrow-kt:arrow-core-retrofit
in my android application 🤦♂️Satyam Agarwal
07/12/2022, 11:38 AMarrow-endpoint
, but its not on 1.1.2 and all my apps are now on 1.1.2
Can I help in bumping versions and releasing ?
cc: @simon.vergauwenjrgonzalez
07/12/2022, 4:33 PMjrgonzalez
07/12/2022, 4:34 PMjrgonzalez
07/12/2022, 4:35 PMLuke
07/12/2022, 6:28 PMMyClass.a.b.c.tap { println(it) }.d.e.f.set(state, newValue)
Yannick Lazzari
07/15/2022, 3:54 PMeffect { ... }
block. Given the following function:
fun function1: Effect<ErrorAdt, String> = effect {
val val1: String = function2()
val val2: String = function3()
return val1 + val2
}
and that both function2
and function3
are possibly throwing exceptions, what is the best way to convert any exceptions they might throw into my ErrorAdt
? Should I simply wrap each call to the functions inside try/catch
blocks and convert them there? Or is there another error handling function that I can call on the effect, where I can centralize all error mapping logic, using some pattern matching on any thrown exceptions? I can't seem to find any in the docs, but just curious. Thank you!phldavies
07/19/2022, 2:48 PMresource {}
DSL release-order bug.rcd27
07/21/2022, 10:51 AMArrow
team was working on better-compiler-plugin-environment-writing for Kotlin. Should I check it out?rcd27
07/21/2022, 6:33 PMEither
and FP
in general is a b*llshit. Now I don't know how to write a good code without that. I send ❤️ to Arrow
team, who have taught me that.phldavies
07/22/2022, 1:18 PMshift("boom")
?
class Test : FreeSpec({
"should this throw?" {
effect {
result { error("💥") }.bind { "boom" }
}.toEither() shouldBe Either.Left("boom")
}
})
Currently it throws. Either.catch({ "boom" }) { error("💥") }.bind()
shifts as you’d expect.dimsuz
07/25/2022, 1:00 PM@optics
would automatically generate companion object
if it's missing.
I'm almost sure that this wasn't done because of some KSP/kotlin plugin API limitation, but maybe there's an issue I can vote on for Kotlin team to make this possible some day?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.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.typealias 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 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 AMNathan Bedell
07/27/2022, 11:47 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.