Jorge Castillo
03/02/2020, 11:14 AMIO.unit
.continueOn(<http://Uniflowdispatcher.dispatcher.io|Uniflowdispatcher.dispatcher.io>)
.flatMap { sideEffect() }
.unsafeRunScoped(scope) { callback ->
// TODO
}
Still adding IO to the combo there is not gonna make much difference given uniflow works eagerly anyways, afaik. You’ll end up needing to unsafe run the IO to enforce the state update to happen right there, @arnaud.giuliani can confirmkluck
03/02/2020, 1:46 PMNeil
03/03/2020, 3:29 PMJakub Pi
03/03/2020, 8:17 PMList<Either<Throwable, C>>
to a List<C>
so that I can pass the cleaned up values to a function. I have a solution but it looks ugly, is there a more idiomatic way? Also welcome comments about approach. Underlying motivation is to start with unvalidated inputs and then only forward the parsed and validated values down to the domain layer which does not have side effects. I will log/handle errors in the next iteration.
.fold(listOf<C>(), {acc, e -> (e.fold({null}, {it})).let {if (it!=null) acc + it else acc}})
Gopal S Akshintala
03/04/2020, 3:15 PMCLOVIS
03/06/2020, 11:25 AMSteven Sherry
03/08/2020, 6:44 PMdnowak
03/09/2020, 1:23 PMval results: List<IO<Either<ListenerError, Unit>>> = ...
and want to convert it to IO<Either<ListenerError, List<Unit>>>
This is what I got to achieve it:
val r = results.sequence(IO.applicative()).fix().map { l ->
l.fix().sequence(Either.applicative()).fix().map { list ->
list.fix()
}
}
Is there any better/nicer way?Nikhil
03/10/2020, 2:07 PMChris Kruczynski
03/10/2020, 4:46 PMGopal S Akshintala
03/12/2020, 12:14 PMAsync<F>, ApplicativeError<S, Nel<E>>
. I achieved it as below:
interface RepoTC<F> : Async<F> {
fun User.isUserCityValid(): Kind<F, Boolean>
fun <S> ApplicativeError<S, Nel<ValidationError>>.userCityShouldBeValid(user: User) = fx.async {
val cityValid = user.isUserCityValid().bind()
if (cityValid) this@userCityShouldBeValid.just(cityValid)
else raiseError(UserCityInvalid(user.city).nel())
}
}
But it just doesn’t feel right, as:
- It can’t be extended if I need other typeclasses.
- I see ApplicativeError
in Async
hierarchy. So do I need both the TCs?
I tried this, but am getting compiler errors due to clashes.
interface RepoTC2<F, S> : Async<F>, ApplicativeError<S, Nel<ValidationError>> {
fun User.isUserCityValid(): Kind<F, Boolean>
fun userCityShouldBeValid(user: User) = fx.async {
val cityValid = user.isUserCityValid().bind()
if (cityValid) just(cityValid)
else raiseError(UserCityInvalid(user.city).nel())
}
}
Can I achieve it just by using Async itself?udalov
03/13/2020, 12:57 PMCaused by: org.jetbrains.kotlin.kapt3.base.util.KaptBaseError: Exception while annotation processing
at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing(annotationProcessing.kt:84)
at org.jetbrains.kotlin.kapt3.base.AnnotationProcessingKt.doAnnotationProcessing$default(annotationProcessing.kt:35)
at org.jetbrains.kotlin.kapt3.base.Kapt.kapt(Kapt.kt:45)
... 26 more
Caused by: java.lang.NullPointerException: e.localizedMessage must not be null
at arrow.common.utils.AbstractProcessor.processElementDoc(AbstractProcessor.kt:75)
at arrow.common.utils.AbstractProcessor.processDocs(AbstractProcessor.kt:101)
at arrow.common.utils.AbstractProcessor.process(AbstractProcessor.kt:107)
at org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor.process(incrementalProcessors.kt)
at org.jetbrains.kotlin.kapt3.base.ProcessorWrapper.process(annotationProcessing.kt:147)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
<...>
Have you met something similar and maybe you know how to workaround this problem?dnowak
03/13/2020, 4:33 PMDaniele Bartorilla
03/13/2020, 8:59 PM@optics
internal sealed class X {
data class Y(val foo: String): X()
object Z: X()
companion object
}
The issue is that the generated extensions are internal: 'public' member exposes its 'internal' receiver type Companion
. Am i doing something wrong?Ahmed Ibrahim
03/14/2020, 10:56 AMEither.applicative().map(sectionsResult, sectionsResult.map(this::gatherAllSaleIds)) {
(sections: List<SalesSectionsQuery.SalesSection>, saleIds: List<SaleId>) ->
// This is a suspend function remoteSalesDataSource.sales(AFFILIATE, saleIds)
}
marc0der
03/14/2020, 11:09 AMtrait Parsers[ParseError, Parser[+_]] {
def run[A](p: Parser[A])(input: String): Either[ParseError, A]
def char(c: Char): Parser[Char]
}
The problem of course comes when declaring the type constructor Parser[+_]
, and when you subsequently try to use a Parser
without the type constructor present, we get an error on the char
parser declaration to the effect of "_type arguments not allowed for type parameters"_. I was hoping that I could use Kind
to solve this problem but not sure how to go about it. Any help would be greatly appreciated!pakoito
03/15/2020, 2:17 AMbmarinovic
03/15/2020, 5:44 PMpakoito
03/16/2020, 11:12 AMmapN
to execute in order. If order matters, then use flatMap
Steven Sherry
03/17/2020, 1:37 PMList<ValidatedNel<E, A>>
and I’m converting that to a ValidatedNel<E, List<A>>
. Is there a more idiomatic way of doing that? The actual flow of data is more like this: List<A> -> List<ValidatedNel<E, B>> -> ValidatedNel<E, List<B>>
. It works, but it feels like there is probably something more “native” to arrow that would handle this kind of flow.than_
03/17/2020, 2:26 PMval useFunc: suspend (A)->B = TODO()
val releaseFunc: suspend (A)->Unit = TODO()
something.bracket(
use = useFunc,
release = releaseFunc
)
?Archie
03/17/2020, 3:39 PMsuspend fun someApi(): IO<SomeObject> {
return IO.effect {
ktorClient.get("<http://someendpoint.com>")
}
}
May I ask for some guidance?pakoito
03/17/2020, 4:18 PMgabib
03/18/2020, 11:09 AMpakoito
03/18/2020, 10:44 PMmyEither.fold({ IO.unit }, { IO.effect { susFun() } }).bind()
Gopal S Akshintala
03/19/2020, 1:09 AMApplicative
) + lazy call functions (with BIO.defer
), so when mapN
processes from left to right, first raiseError
should halt the processing and rest of the functions shouldn’t be called, @pakoito helped me come-up with this approach, but I am facing 2 problems:
1. I am using BIO, but raiseError
from ApplicativeError
doesn’t return a Kind2
, how can I get around it?
2. IO.defer{..}
has this compiler error: Type mismatch. Required: () → IOOf<String, ???> Found: () → Unit
for both my extension functions raiseAnError()
and justString()
Please help. Thanks.
@Test
fun `IO ApplicativeError 2`() {
val product =
IO.applicativeError<String>().mapN(
IO.defer { raiseSomeError() },
IO.defer { justString() }
) {}.fix().unsafeRunSyncEither()
product.fold({ assertEquals("error", it) }, {})
}
private fun <S> ApplicativeError<S, String>.raiseSomeError(): Kind2<S, String, Unit> {
println("raising an error")
return raiseError("error")
}
private fun <S> ApplicativeError<S, String>.justString(): Kind2<S, String, Unit> {
println("This should not be printed")
return just("just")
}
Satyam Agarwal
03/19/2020, 4:46 PM0.10.5
release github project is all done. When its getting released 😅 I am waiting for coroutine integration so that I can make my logs nicer by attaching correlation ids to them 😄bjonnh
03/19/2020, 10:27 PMkyleg
03/20/2020, 3:32 PMRef<ForIO, MyClass>
and a StateT<ForIO, MyClass, Unit>
, what is the best way to make these two work together (using the StateT
to update the value wrapped in Ref
?) I have to unpack the Ref
, pass it into the StateT
, and use the result to update the Ref
. I’m not sure how to do that without
myRef.update { oldState ->
val (newState, _) = myStateT.runM(IO.monad(), oldState).unsafeRunSync()
newState
}
but I know the unsafeRunSync
is the stinkiest code smell there ever was.kartoffelsup
03/20/2020, 6:47 PMkartoffelsup
03/20/2020, 6:47 PMkyleg
03/20/2020, 7:36 PM+state {}
thing that are a step backwards from immutability. I’d be interested to see what people suggest, as Compose is something I’ve been playing around with, too.raulraja
03/20/2020, 10:02 PMkartoffelsup
03/20/2020, 10:05 PM