Cody Mikol
09/21/2021, 2:13 PMNel
?
I’m doing something along the lines of
list.parTraverseValidated(Nel.semigroup(), ::foobar)
but this is not correctScott Christopher
09/22/2021, 2:26 AMQueue
type no longer exists in Arrow (presumably when IO
went away?). I was looking to build a simple rate limiter using the bounded queue and Schedule
if anyone has any suggestions for alternatives.Benoît
09/22/2021, 10:10 AMjean
09/23/2021, 7:51 AMList<Either<Error, Id>>
to a Either<Error, List<Id>>
? I want a Either.Left
return as soon as possible, not a list of all result eventually containing errors. Either an error immediately when something fails or a list of valid resultivanmorgillo
09/23/2021, 9:17 AMLeo Laudouard
09/23/2021, 10:30 AMTimeoutCancellationException
, which is a CancellationException
.
Hence, when using Either.catch
to make a request, the exception is considered 'fatal', since 793a51edce
, and re-thrown.
My question is, why is this considered fatal ?
Thanks !Morten Andersen-Gott
09/23/2021, 12:26 PMandThen
which would be nice to have in arrow. Currently one can achieve something functionally equal with withEither
like this:
Validated.catch { "0".toInt() }.toValidatedNel().withEither { it.flatMap { Either.catch { 1 / it } }
however going through an either instance feels unnecessary when one is still operating on validations. So perhaps something like this:
fun <E,A, B> Validated<E, A>.andThen(f: (A) -> Validated<E, B>) :Validated<E, B> {
return when(this){
is Valid -> f(value)
is Invalid -> this
}
}
Validated.catch { "0".toInt() }.toValidatedNel().andThen { Validated.catch { 1/it } }
Example is a simple, but it is quite useful when you want to do input validation first, and then if valid continue with more advanced validation rulesPratik Tandel
09/24/2021, 4:22 AM.map
/ .flatMap
from arrow? right now it seems i will have to write extension functions that do something similarPratik Tandel
09/24/2021, 6:58 AMValidatedNel<Error, List<Result>>
— basically i’d like to aggregate all errors whenever it failedLuke
09/24/2021, 9:19 PM@optics
to modify a data class
. Let's say I have a data class Foo(val list: List<Bar>)
, is there an operator to modify the only element in the list that matches a predicate?gammax
09/27/2021, 3:24 PMMorten Andersen-Gott
09/27/2021, 7:04 PMarrow/arrow-site/vendor/bundle/ruby/3.0.0/gems/kramdown-1.17.0/lib/kramdown/parser/html.rb:10:in `require': cannot load such file -- rexml/parsers/baseparser (LoadError)
Is there an easy fix? Not really well versed in gems and jekylldnowak
09/27/2021, 9:38 PM() -> Either<Failure, Result>
and
• (Failure) -> Error
to () -> Either<Error, Result
.
All I want to do is to “decorate” a function returning Either
with error mapping.pakoito
09/28/2021, 1:59 PMbenkuly
09/28/2021, 7:05 PMEric
09/29/2021, 5:15 PMList<Validated<Foo, Unit>>
to a single Validated<Bar, Unit>
. I’m having trouble figuring it out. This works:
val failed = values().map {
it.validate(vehicleSettingEntity, states) // a Validated<ValidationError, Unit>
}.filterIsInstance<Validated.Invalid<ValidationError>>().map { it.value }
return when {
failed.isEmpty() -> Unit.valid()
else -> ValidationResult(failed).invalid()
}
But it feels like some sort of fold
might be better here. Can anyone provide a little guidance?soulbeaver
09/30/2021, 12:15 PMpersonalData.validate().zip(
Semigroup.nonEmptyList<ValidationError>(),
taxData.validate(),
productData.validate()
) { personData, taxData, productData -> Person(...) }
However, all of the sub-objects have a different type:
• personalData.validate() -> ValidatedNel<ValidationError, PersonalData>
• taxData.validate() -> ValidatedNel<ValidationError, TaxData>
Which means that instead of the above I'm currently doing a bunch of manual checks like so:
val validatedPersonalData = when (val result = personalData.validate()) {
is Valid -> result.value
is Invalid -> validationErrors.addAll(result.value)
}
Over and over again until finally
return if (validationErrors.isNotEmpty())
validationErrors.invalidNel()
else
Person(validatedPersonalData, validatedTaxData, validatedProductData)
Is there a better way of doing this?julian
09/30/2021, 8:15 PMjean
10/04/2021, 6:41 AMEither<Error, x>
, I got it too work but the code is rather cumbersome and difficult for anyone else to figure out quickly. This is a simplified version, but it works the same way :
class A
class B
class C(
val val1: String,
val val2: String,
val val3: String,
val a: A,
val b: B,
)
fun getA(val1: String): Either<Exception, A> = Either.Right(A())
fun getB(val1: String): Either<Exception, B> = Either.Right(B())
fun getCs(): Either<Exception, List<CBuilder>> = Either.Right(listOf(CBuilder("val1", "val2", "val3")))
class CBuilder(
val val1: String,
val val2: String,
val val3: String,
)
class EitherTest {
@Test
fun buildC() {
getCs().flatMap { builders ->
builders.map { builder ->
getA(builder.val1).flatMap { a ->
getB(builder.val1).map { b ->
C(builder.val1, builder.val2, builder.val3, a, b)
}
}
}.sequenceEither()
}
}
}
Is there a way to simplify the two first map
in one operator, and is there a way to avoid consequent nesting of map
and flatmap
?Cody Mikol
10/05/2021, 2:51 AMbifoldLeft
have left
in its name? It seems similar to fold
with the addition of an extra initial property passed in to both the left and right lambdas. Would it make more sense for this to just be named bifold
?Mickey Donaghy
10/05/2021, 7:47 AMWriterT
these days? I want to use Either-like and Writer-like effects togetherAlexander Levin
10/05/2021, 6:15 PMConst
assuming we don't have HKT simulation anymore?
• Same question for widen
(code examples seems to be working just fine without widen
call)
• Is there a reason to implement most functions inside of Either/Validated/etc or is it just the matter of preference? (I think standard library usually extract non-essential functions as extensions as much as it's possible considering interop)
• Is there any code examples about using Arrow with any popular framework/library like Ktor or Spring?
• What's the usage of Endo
? (didn't really find it in the repo)niltsiar
10/06/2021, 8:24 AMNathan Bedell
10/06/2021, 3:27 PMSequence
monad (which I think would be similar to the List monad in Haskell), or any other similar non-deterministic monad using Arrow-style comprehension notation using coroutines?
I know there are examples of "result type" comprehensions in arrow core (e.x. Either
), and I've been able on my own to figure out how to build a monad comprehension syntax for a ReaderT IO
-like monad (this was actually pretty easy) -- but I can't for the life of me figure out how to encode a non-deterministic monad like Sequence
using the methods of Arrow.
Has anyone attempted this, or have any working examples? As I understand, the problem is basically to encode the monad as a sub-monad of the continuation monad (i.e the whole "continuations are the mother of all monads" thing) -- but I'm not experienced enough with continuations be able to grok that yet.Connor Ford
10/14/2021, 2:17 PMEither
has changed as ap
is no longer resolved in this statement:
location.ap(name.map(action))
where location
and name
are both of type Either<String, String>
and action
is (String) -> (String) -> String
.
How can I find out what the updated sytnax should be?Peter
10/14/2021, 7:06 PMfun saveSession(session: Session): Either<Throwable, Unit>
fun getSession(id: SessionID): Either<Throwable, Session>
for a specific implementation (Redis vs Relational vs mock) with additional dependencies:
fun saveSession(connection: RedisConnection, session: Session): Either<Throwable, Unit>
fun getSession(connection: ResdisConnection, id: SessionID): Either<Throwable, Session>
this prevents grouping functions as an interface, even if using partial functions (i think)
or using an interface OO-style:
class RedisSessionManager(connection: RedisConnection): SessionManager {
fun saveSession(session: Session): Either<Throwable, Unit>
fun getSession(id: SessionID): Either<Throwable, Session>
}
side effects aside, no longer pure with the global external dependency
Reader monad perhaps? not sure one ever gets away from the external implementation specific dependency (eg: connection), what approaches have you taken?conner
10/15/2021, 5:45 PMValidatedNel
?
fun buildMyObjectObject(token: String?, name: String?): ValidatedNel<Error, MyObject> =
Validated.fromNullable(token, { MissingField("token") }).toValidatedNel().zip(
Validated.fromNullable(name, { MissingField("name") }).toValidatedNel()) { token, name ->
MyObject(token, name)
}
it kind of feels like i "shouldn't" need to call toValidatedNel
for each Validated
Nathan Bedell
10/15/2021, 6:56 PMjulian
10/17/2021, 6:35 AMCoproduct
? How come? And what's the recommended alternative?Oliver Eisenbarth
10/17/2021, 8:53 AMOliver Eisenbarth
10/17/2021, 8:53 AMraulraja
10/18/2021, 8:53 AMPostiveInt
, collection access and others that show outcomes of compilation with and without the plugin appliedOliver Eisenbarth
10/19/2021, 9:33 AMno-arg
plugin is used) public constructor. doh
Please excuse me for giving advice without trying out things first. I'm still on parental leave and kinda lazy. I will tell the guy. 🙂
The new plugin sounds exciting. I will check out the tests! Thanks for making Arrow so accessible, you guys rock. 🤘