Jascha Smacka
06/18/2021, 2:28 PMDorian Codes
06/22/2021, 3:40 PMdata class Config(val map: Map<String, String>) {
suspend fun <A> parse(read: Read<A>, key: String) = either<ConfigError, A> {
val value = Validated.fromNullable(map[key]) {
ConfigError.MissingConfig(key)
}.bind()
val readVal = Validated.fromNullable(read.read(value)) {
ConfigError.ParseConfig(key)
}.bind()
readVal
}
In particular I wasn't able to call bind()
from a Validated
. Is that something I am missing? Also I noticed that bind()
is not listed among the functions for Validated
in the docs. I'm using arrow-core version 0.11.0
Miłosz Korman
06/24/2021, 1:55 PMPedro Sena
06/28/2021, 7:25 PMkierans777
06/29/2021, 4:05 AMfun doSomething(): ((Class<T>) -> T) -> T
However because lambda expressions can't have generic types, this doesn't compile for me.ds3fdfd3
06/29/2021, 1:31 PMeval's
map and flatmap. I have this code but it doesn't compile as doSomething()
can only be called withing coroutine body.
import arrow.core.Eval
import kotlinx.coroutines.runBlocking
fun main(): Unit = runBlocking {
Eval.now(10)
.map { doSomething() }
.value()
}
private suspend fun doSomething(): Int {
println("do something")
return 20
}
stojan
06/30/2021, 8:09 AMAlvaro Blazquez checa
06/30/2021, 9:04 PMSrki Rakic
07/05/2021, 5:15 PMList<Error>
out of List<Either<Error, Result>>
?Daniel Ryan
07/06/2021, 3:34 PMval ids = listOf(1, 2, 3)
and I have a function that returns a valid thing for a given identifier fun getThing(id: String) : Either<String, Thing?>
what is the best way to execute the getThing function for all ids in the list until a Thing is found, or an either.left is encountered? Traverse is close to what I need, but it will involve unnecessary database calls; I will like to exit processing as soon as a match is found.julian
07/06/2021, 7:40 PMEither
? I could use fold
. But that doesn't seem quite right since fold
`s intent seems to be more on producing a value, not performing side-effects.CLOVIS
07/08/2021, 4:48 PMLidonis Calhau
07/10/2021, 10:07 PMSergei Zubov
07/14/2021, 12:40 PMsuspend () -> A
instead of IO<A>
. Does this literally means that signature of the function that produces a side-effect should be suspend () -> A
, or it can be suspend (parameter1, parameter2...) -> A
? Which one is correct and why:
data class Message(val content: String)
suspend fun sideEffectProducer(message: Message) = println(message)
or
data class Message(val content: String)
suspend fun Message.sideEffectProducer() = println(this)
And a follow-up question - how functions with side effects differ from pure functions that use either
block and .bind()
results? Both of them are suspend
carbaj0
07/15/2021, 8:10 AMsimon.vergauwen
07/15/2021, 10:58 AMSergei Zubov
07/16/2021, 10:36 AMPeter
07/19/2021, 10:54 PMeither
lazy blocks do not play well with the coroutine dump generator? i use (the scarcely documented) way of sending a process a 5 signal to get a coroutine dump (similar to 3 for a thread dump) … the line numbers often don’t make sense (larger than the file contains, refers to desugared code?). in every case i believe the coroutine is suspended somewhere within the either
block (though hard to be 100% sure given the line number inaccuracy)
the top of the coroutine stack frames is always the function containing the either
block, i was hoping to see more detailAndrei Bechet
07/22/2021, 11:40 AMeither
with coroutines in Springboot and I am not sure I fully understand what’s happening.
Take for example this code:
suspend myServiceFunction() = either {
val r1 = someApiCall(...).bind()
// Either<Fail,Res1>
val r2 = someOtherApiCall(...).bind()
// Either<Fail,Res2>
combineOperation(r1, r2) // Either<Fail, Res2>
}
My question is the following: how can we best make someApiCall
and someOtherApiCall
run in parallel? Is the bind
for obtaining r2
is waiting for r1
to first get returned? Thanks 🙂carbaj0
07/25/2021, 10:11 AMMarko Novakovic
07/26/2021, 7:48 AMEither
and calls itself functional programming nor something too complicated for purposes of showing theory in practice.Oliver Eisenbarth
07/28/2021, 3:05 PMrcd27
07/29/2021, 10:13 AM.getOrHandle
to return List<ContractorTas>
, however compiler thinks there is List<Any>
. What am I doing wrong?simon.vergauwen
08/01/2021, 8:15 PMLidonis Calhau
08/03/2021, 2:50 PMValidated<ValidationError, Enum1>, Validated<ValidationError, Enum2> -> Validated<Nel<ValidationError>, Pair<Enum1, Enum2>>
Peter
08/03/2021, 8:53 PMEither.catch
is strict in evaluating it’s supplied function, is there a way to catch an Exception from an effect? eg
suspend findThing(): Thing {}
Either.catch { findThing() } // ???
rcd27
08/04/2021, 8:24 AMEither
monad from Retrofit
interfaces. What do you think I've recently got from my partner? Brilliant idea: to skip handling each Left
and just throw Exceptions. Remember the song?: lonelyyyy, I'm sooo loonelyyyy 😭rcd27
08/13/2021, 9:34 AMOpenCV
. I believe that I should implement something reactive + FP: imagine there is a bar where we can "just add new processing operation". This will result in a "list of operations", applied: rawImage -> op1-> op2 -> op3 -> processedImage
. where all opX
take result of the previous one. That would be great to memoize the result of operations, so that if I change some characteristics in op3
for example (each operation has its own arguments), that wouldn't lead to recomputation of op1
and op2
. Which way should I dig in, how do you think? I think this is ideal for FP, what do you say?noone
08/14/2021, 7:51 PMDario Valdespino
08/15/2021, 5:47 PMcrossinline suspend
functional parameters. Fixed in Kotlin 1.5.30-RC.
Is it a known bug that either {}
does not work properly with value
classes? For example, the following code:
@JvmInline
value class Metadata(val map: Map<String, String>)
fun reproduceBug() = either<Unit, Metadata>{
Metadata(emptyMap())
}
Whenever I use debug to see the result of the function, it will contain a Right({})
, meaning that the right value actually contains the underlying Map
instead of the Metadata
wrapper. This causes a ClassCastException
in runtime when using bind
. Am I missing something?Dario Valdespino
08/15/2021, 5:47 PMcrossinline suspend
functional parameters. Fixed in Kotlin 1.5.30-RC.
Is it a known bug that either {}
does not work properly with value
classes? For example, the following code:
@JvmInline
value class Metadata(val map: Map<String, String>)
fun reproduceBug() = either<Unit, Metadata>{
Metadata(emptyMap())
}
Whenever I use debug to see the result of the function, it will contain a Right({})
, meaning that the right value actually contains the underlying Map
instead of the Metadata
wrapper. This causes a ClassCastException
in runtime when using bind
. Am I missing something?simon.vergauwen
08/16/2021, 11:51 AMvalue class
doesn’t exist at runtime. IIRC this bug is related to suspend
+ value class
and is “unrelated” to the encoding inside either { }
.
For this reason I’m currently not using value class
yet in production (😞). So this is fixed in 1.5.30?Dario Valdespino
08/16/2021, 12:33 PMsimon.vergauwen
08/16/2021, 12:42 PM