Katarzyna
11/28/2022, 1:41 PMP A
11/28/2022, 8:44 PMipolyzos
11/30/2022, 7:42 AMResource
or a Bracket
2. Using bracket when the url is invalid for example
bracketCase(
acquire = { openConnection("<https://someURL>") },
use = { connection ->
connection.fetch()
},
release = { connection, exitCase ->
when(exitCase) {
is ExitCase.Completed -> println("Completed: $exitCase")
is ExitCase.Cancelled -> println("Cancelled: $exitCase")
is ExitCase.Failure ->
println("Failure: $exitCase")
}
println("Closing connection")
closeConnection(connection)
}
)
i do get the exit case but i see the exception is still thrown.. What's the best way to handle the exception properly? do i need to wrap the computation with an either
block?
Failure: Failure(failure=java.net.UnknownHostException: someURL)
Closing connection
Exception in thread "main" java.net.UnknownHostException: someURL
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:567)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
at java.base/java.net.Socket.connect(Socket.java:633)
at java.base/sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:304)
at java.base/sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:174)
finally since its a SSE connection do u think there are other things that need to be accounted for other than running the processing of the events in the Dispatchers.IO pool?Piotr Krzemiński
11/30/2022, 9:14 AMsimon.vergauwen
11/30/2022, 9:25 AMChris Lee
11/30/2022, 3:26 PMprivate fun someFun() : Either<String,Int> {
return either.eager {
Either.catch({ it.message ?: "No message" }) {
42 // this would be a call hierarchy that may throw exceptions
}.bind() // Hmmm. need to unwrap either created from 'catch' to get a value for 'eager'
}
}
P A
12/01/2022, 1:13 AMval theEither: Either<Any, D> = either {
val x : Either<A, B> = serviceA.something()
val xValue : B = x.bind()
val y : Either<C, D> = serviceB.somethingElse(x)
val yValue : D = x.bind()
yValue
}
P A
12/01/2022, 3:47 AMsomething
and somethingElse
use context receivers(context(EffectScope<A>)
and `context(EffectScope<C>)`respectively) as there is no obvious way to mapLeft A and C within the either
block to, say, map A and C to a new error hierarchy Z(EffectScope<Z>
).CLOVIS
12/01/2022, 9:17 AMsimon.vergauwen
12/01/2022, 9:17 AMeffect
and Effect
directly?
How problematic would a small migration be for your codebase? The migration would entail refactoring arrow.core.continuations.*
to arrow.core.raise.*
and adding some imports for methods that become extension methods.
For those using Either
& either
or similar it would only require refactoring arrow.core.continuations.either
and arrow.core.continuations.ensureNotNull
to arrow.core.raise.*
without any additional changes.
Within the Arrow team we discuss back-porting the 2.x.x Raise
API to 1.x.x such that migration is eased. I'm trying to figure out how much the effort would be for existing users.P A
12/04/2022, 4:08 AMP A
12/05/2022, 12:44 AMP A
12/05/2022, 6:03 AMP A
12/05/2022, 6:07 AMval json = Json {
serializersModule = SerializersModule {
contextual(NonEmptyList::class){args -> NelSerializer(args[0])}
}
}
ipolyzos
12/05/2022, 7:30 AMAlejandro Serrano Mena
12/05/2022, 8:42 AMTraversal
, Optional
, Lens
and Prism
and remove the restDan Miller
12/05/2022, 5:54 PM(A) -> Either<EE, B>
to an Either<E, Option<A>>
?
The expected behavior is:
1. Either.Left<E>
remains unchanged
2. Either.Right<None>
remains unchanged
3. Either.Right<Some<A>>
, with f:
returning an Either.Left<EE>
, returns the Either.Left<EE>
4. Either.Right<Some<A>>
, with f:
returning an Either.Right<B>
, returns the Either.Right<B>
as a Either.Right<Some<B>>
Sample implementation and tests are in the 🧵CLOVIS
12/05/2022, 10:07 PMJoão Esperancinha
12/06/2022, 7:33 AMKatarzyna
12/06/2022, 1:25 PMsimon.vergauwen
12/07/2022, 2:06 PMEffectScope
. arrow intensifiesCLOVIS
12/07/2022, 4:45 PMJordi Pradel
12/07/2022, 5:35 PMcontext(Raize<...>)
. e.g.:
context(Raise<AccountNotFound>)
suspend fun getNumberOfOperationsIn(accout: AccountNumber): Natural
I understand Either
will still be idiomatic for pure functions that may return an error (that is programs whose only side effect can be to fail with a domain error). I'm thinking of smart constructors for my domain classes (e.g. a function that takes an Int
and returns either a NaturalNumber
or a IllegalNaturalNumber
error). I wouldn't like to make such a constructor a suspend fun
because it is otherwise a pure function.
I have some questions regarding this new approach (to apply whenever Arrow 2 and Kotlin's context receivers are production ready):
1. Is the usage of Either
I described the expected?
2. Is programming such pure functions that can fail the purpose of the eagerEffect
function?
3. Does the `effect`function still have idiomatic usages?CLOVIS
12/07/2022, 6:29 PMLuke
12/07/2022, 6:53 PMCLOVIS
12/07/2022, 7:56 PMsealed class Tree {
class Leaf(val x: Int) : Tree()
class Node(val x: Int, val children: Map<String, Tree>) : Tree()
}
What would be the Optics way of filtering nodes based on some criteria throughout the entire tree (recursively)?Marko Novakovic
12/07/2022, 9:05 PMLuke
12/08/2022, 3:19 PM@optics
data class Foo(
val bar: Either<Throwable, Bar>,
}
How would I focus bar
only if it's a Either.Right
. I expected something like Foo.bar.right.modify(...)
to exist but it doesn't seem so...Sam Pengilly
12/13/2022, 11:57 PMEffect
and Eval
. At first glance I see that Eval isn’t really an extension of suspend () -> A
but instead seems to have the purpose of collapsing potentially large callstack operations. Effect seems to provide functions like attempt
and fold
but seems a bit more like a wrapper around suspend () -> A
. Is it there to provide an extra layer of “semantics”, such as making it clear that a function returns a side-effecting operation versus just a suspending one? Should Effect
be used as a return type over suspend () -> A
? or are there use-cases for both?nacyolsa
12/14/2022, 9:52 AMShiftCancellationException(Shifted Continuation)
is it some known issue?