i-walker on is-effect-overview
rename traverseX and sequenceX … feat: contravariance for R, A i… Merge branch 'main' into is-eff… (compare)
i-walker on all
feat: contravariance for R, A i… Merge branch 'main' into renova… (compare)
i-walker on is-deprecate-flatmap-map-eagereffect
feat: contravariance for R, A i… Merge branch 'main' into is-dep… (compare)
i-walker on is-contravariant-eager-effect
i-walker on main
feat: contravariance for R, A i… (compare)
renovate[bot] on all
Update all dependencies | data… (compare)
so, I might be asking a trivial question, but for once my searching skills are failing me :/ so here goes:
I have val as: List<A> = TODO()
I have a val aToB: (a: A) -> Either<C, B>
what I want is to stop on the first error and return Either<C, List<B>>
.
For now I have as.traverse(Either.applicative(), aToB).fix().map { it.fix() }
but isn't there a "cleaner" way to do this, so I don't have to call fix
?
'java.lang.Object arrow.core.Either$Left.getA()'
java.lang.NoSuchMethodError: 'java.lang.Object arrow.core.Either$Left.getA()'
at io.kotest.assertions.arrow.either.MatchersKt$beLeft$1.test(matchers.kt:72)
at io.kotest.assertions.arrow.either.MatchersKt$beLeft$1.test(matchers.kt:65)
at io.kotest.matchers.ShouldKt.invokeMatcher(should.kt:36)
at io.kotest.matchers.ShouldKt.should(should.kt:31)
at io.kotest.assertions.arrow.either.MatchersKt.shouldBeLeft(matchers.kt:63)
implementation("io.arrow-kt:arrow-core:0.13.1")
implementation("io.arrow-kt:arrow-syntax:0.13.1")
kapt("io.arrow-kt:arrow-meta:0.13.1")
My workaround is to build the Couroutine with
runBlocking {
either {
//...
}
}
But i dont think this is the way iam supposed to do this
f compose g
in my code. However why is compose
an infix function? That's the sort of documentation I'm after, and I'm hoping someone can point me in the right direction. :)
IO
in favour of suspend () ->A
. But I don't quite understand how to use it. For IO
, a function that has a side effect wraps its return into IO<T>
. And all callers to that function also wraps in IO
, up to the end of the world. But how do I deal with the suspend () -> A
approach with side effects that require inputs, i.e. fetching entity by ID from the DB? That function is suspend (ID) -> A
, not suspend () -> A
. As I understand from the reasoning behind switching to it from IO
, using functions with input parameters can also work, but I'm unsure. Thank you :)
Hello, I'm trying to update a list of items, where each item has a separate type, but some items share the same properties. It looks like this
sealed class Item
data class Ext1(val a: Int) : Item()
data class Ext2(val a: Int, val b: String) : Item()
data class Ext3(val b: String) : Item()
val items = listOf(Ext1(1), Ext2(1, "1"), Ext3("1"))
I'm trying to use a combination of a Traversal
along with a Prism
and some Lenses
.
typealias ALens<S> = PLens<S, Item, Int, Int>
val ext1ALens = ALens(get = Ext1::a, set = Ext1::copy)
val ext2ALens = ALens(get = Ext2::a, set = Ext2::copy)
val aPrism = PPrism<Item, Item, ALens<in Item>, Item>(
getOrModify = {
when (it) {
is Ext1 -> ext1ALens.right()
is Ext2 -> ext2ALens.right()
else -> it.left()
}
},
reverseGet = ::identity
)
val traversal = PTraversal.list<Item>().modify(items) { item ->
aPrism.modify(item) { lens ->
lens.modify(item) { it * 2 }
}
}
The problem is that I can't make getOrModify
right. Is it possible to define a generic lens
that will be able to handle different subtypes of Item
?
I have a short question regarding traverse in arrow. as far as I am aware since 0.13.1 traverse
is now directly implemented like with traverseEither
and does no longer work with typeclasses because of their deprecation.
However, I cannot find an implementation for traverseOption and had to write my own.
Is there a reason for this or was I just unable to find an implementation?
// map2 is actually copied from https://www.manning.com/books/functional-programming-in-kotlin
private fun <A, B, C> map2(
oa: Option<A>,
ob: Option<B>,
f: (A, B) -> C
): Option<C> =
oa.flatMap { a ->
ob.map { b ->
f(a, b)
}
}
private fun <A, B> List<A>.traverse(
f: (A) -> Option<B>
): Option<List<B>> {
return this.map(f).fold(Option(emptyList())) { acc: Option<List<B>>, option: Option<B> ->
map2(
acc,
option
) { list: List<B>, b: B ->
list + b
}
}
}
Kind
from Arrow in a new Android project. However arrow.Kind
is not valid. It can use the other Arrow types like Either
or Option
. I added this to my build.gradle
implementation "io.arrow-kt:arrow-fx-coroutines:0.13.2"
. I was kind of wondering if the higher kinded stuff is in some other package?
Hi, I have problem while trying to use Monad Comprehension with ArrowKt Core.
fun create(order: Order): Either<OrderError, Order> = either.eager {
val something = fetchSomething(order.id).bind()
val mapped = order.map(something).bind()
val stored = orders.save(mapped)
stored
}
Everything is fine except that this function returning order and not stored. :/
Either<OrderError, Order>
because I want to return mapped and stored object. Unfortunately it is compiling but returning order that was passed to fun.bind()
? After orders.save(mapped)
?
I wrapped this in Either.Right(orders.save(order)).bind()
but result is the same. How can I provide you more function signatures/types?
I'm using Spring and invoking this either.eager like that:
@PostMapping
fun add(@RequestBody order: Order): ResponseEntity<*> = handler.create(order)
.map { ResponseEntity.status(201).body(order) }
.getOrHandle { ResponseEntity.status(it.status).body(it.message) }
Can be this somehow causing trouble?
Either<DomainError,A>
val o: List<Either<DomainError, List<Policy>>> = domainObjects.map { ev ->
getConfigVersion(configId, versionId).flatMap { piConfigVersion ->
isEditable(piConfigVersion).flatMap { validatedPiConfigVersion ->
addOrUpdateIncidentAction(validatedPiConfigVersion, ev).flatMap {
updateScriptBehaviourPolicies(validatedPiConfigVersion, ev)
}
}
}
}
`
either.eager<DomainError, List<Policy>> {
val piConfigVersion = getConfigVersion(evRequest.configId, evRequest.versionId).bind()
val isEditable = isEditable(piConfigVersion).bind()
val incidentAction = addOrUpdateIncidentAction(piConfigVersion, evRequest.ev).bind()
val updatedIncidentAction = saveIncidentActions(incidentAction).bind()
val policies = updateScriptBehaviourPolicies(piConfigVersion, evRequest.ev).bind()
val updatedPolicies = savePolicies(policies).bind()
updatedPolicies
}
Hi all, I'm having trouble achieving something using Prisms. Is there a version of .modify()
that let's me transform into another type?
Consider this simple example:
@optics
sealed class State{
companion object {}
data class Response(val msg: String?): State()
object Error: State()
}
// this does not compile
State.response.modify(State.Response(null)) { response ->
if (response.msg == null) {
State.Error
} else {
response
}
}
Is there a function that let's me do type transformation when modifying? Thanks!