kobby
06/18/2020, 11:42 AMEither.Right("SOMETHING").map{it.toLowerCase()}
and I'm getting Cannot access 'arrow.Kind' which is a supertype of 'arrow.core.Either'
I already have arrow-core 0.10.5 and arrow-core-data 0.10.5 is there another library I need to bring in?VladKopanev
06/18/2020, 1:13 PMfun <A, B, C, D> fromNullable(a: A?, b: B?, c: C?, f: (A, B, C) -> D): D?
pakoito
06/18/2020, 7:21 PMjem
06/20/2020, 5:15 AM/**
* Extension function that fixes `Reader` so that you can `map` without needing to pass
* `arrow.core.Id.monad()` explicitly.
*/
fun <D, A, B> Reader<D, A>.map(f: (A) -> B): Reader<D, B> {
return this.map(arrow.core.Id.monad()) { f(it) }
}
/**
* Extension function that fixes `Reader` so that you can `flatMap` without needing to pass
* `arrow.core.Id.monad()` explicitly.
*/
fun <D, A, B> Reader<D, A>.flatMap(f: (A) -> KleisliOf<D, ForId, B>): Reader<D, B> {
return this.flatMap(arrow.core.Id.monad()) { f(it) }
}
Is there any blocker for actually just making Reader work this way in the lib? Is there any other monad instance that is valid for Reader?marc0der
06/20/2020, 10:58 AMstojan
06/20/2020, 2:41 PMoverride fun open(
no: String,
name: String,
rate: Option<BigDecimal>,
openingDate: Option<LocalDate>,
accountType: AccountType
): AccountOperation<Account> = Kleisli.invoke { repo ->
EitherT(
repo.query(no).flatMap { accountOptionOrError ->
accountOptionOrError.fold(
{ IO { MiscellaneousDomainExceptions(it).left() } },
{ accOpt ->
accOpt.fold(
{
when (accountType) {
AccountType.CHECKING -> createOrUpdate(
repo,
Account.checkingAccount(no, name, openingDate, None, Balance())
)
AccountType.SAVINGS -> rate.map { r ->
createOrUpdate(
repo,
Account.savingsAccount(no, name, r, openingDate, None, Balance())
)
}.getOrElse { IO { RateMissingForSavingsAccount.left() } }
}
},
{ IO { AlreadyExistingAccount(<http://it.no|it.no>).left() } }
)
}
)
}
)
}
the future:
override suspend fun AccountRepository.open(
no: String,
name: String,
rate: BigDecimal?,
openingDate: LocalDate?,
accountType: AccountType
): Either<AccountServiceException, Account> = either {
val existing = query(no).mapLeft { MiscellaneousDomainExceptions(it) }.bind()
existing.rightIfNull { AlreadyExistingAccount(no) }.bind()
val accountOrError = when (accountType) {
AccountType.CHECKING -> Account.checkingAccount(no, name, openingDate, null, Balance())
AccountType.SAVINGS -> {
val r = rate.rightIfNotNull { RateMissingForSavingsAccount }.bind()
Account.savingsAccount(no, name, r, openingDate, null, Balance())
}
}
createOrUpdate(this@open, accountOrError).bind()
}
the future is bright 😄julian
06/21/2020, 2:13 AMGopal S Akshintala
06/21/2020, 2:51 AMfilterOrElse
equivalent for BIO?
Currently I had to write like this to set BIO to left of right state based on a boolean result (which feels boilerplate)
val example: (IO<String, Int>) -> IO<String, Any?> =
{ valueIO ->
valueIO.map(::someBooleanResult)
.flatMap { if (it) IO.just(it) else IO.raiseError("error") }
}
pakoito
06/21/2020, 2:51 PMFudge
06/21/2020, 5:16 PMdata class X(val name : String)
data class Y(val x1: X, x2: X, x3 :X, x4: X)
Is there an easy way to change the name
value of all ocurrences of X
instances in Y
? Using optics perhaps?
Something like this:
val y = Y(...)
val newY = changeAllNames(y) {it + "foo"}
rt
06/21/2020, 8:27 PM//metadebug
-annotated classes to be displayed on compilation? is there some compiler switch or something? I cloned the arrow-meta-examples project but nothing gets printed into compiler output even though //metadebug
is clearly theresimon.vergauwen
06/22/2020, 9:20 AMhttps://www.youtube.com/watch?v=6sw8GAhUJz0▾
julian
06/22/2020, 7:09 PMclass G
class H
interface A<T> {
fun T.foo(t: T): T
}
interface B : A<G>
interface C : A<H>
interface E : B, C // Compiler error: Type parameter T of 'A' has inconsistent values: InterfaceComposition.G, InterfaceComposition.H
Is there a way to get around the compiler error?
My use case is that A is a generic handler of events of type T. So B and C are specific handler implementations for the events G and H.
I would like to be able to do:
val a: A = TODO()
when (a) {
is B, is C -> a.foo(..)
else -> TODO()
}
Without a common base interface, I'd have to do:
val a: A = TODO()
when (a) {
is B -> a.foo(..)
is C -> a.foo(..)
else -> TODO()
}
Thanks!Rizary
06/22/2020, 10:00 PMjulian
06/23/2020, 5:23 PMraulraja
06/24/2020, 10:59 AMbjonnh
06/24/2020, 6:59 PMbjonnh
06/24/2020, 7:56 PMbjonnh
06/24/2020, 8:24 PMFelix
06/25/2020, 3:55 PMjulian
06/25/2020, 11:17 PMsyntax
used in naming classes or packages in Arrow or apps that use Arrow? I've seen this pattern before, but I don't recall where. Is it used interchangeably with the term ops
? Or maybe it was in Scala code...julian
06/26/2020, 10:22 PMjulian
06/28/2020, 5:33 PMSasha Chepurnoi
06/29/2020, 2:24 PMmatthew graf
06/29/2020, 8:31 PM[2020-06-29T19:32:38.437Z] * What went wrong:
[2020-06-29T19:32:38.437Z] Execution failed for task ':core:kaptGenerateStubsKotlin'.
[2020-06-29T19:32:38.437Z] > Could not resolve all files for configuration ':core:compileClasspath'.
[2020-06-29T19:32:38.437Z] > Could not resolve io.arrow-kt:arrow-mtl:0.11.0-SNAPSHOT.
[2020-06-29T19:32:38.437Z] Required by:
[2020-06-29T19:32:38.437Z] project :core
[2020-06-29T19:32:38.437Z] > Could not resolve io.arrow-kt:arrow-mtl:0.11.0-SNAPSHOT.
[2020-06-29T19:32:38.437Z] > Unable to load Maven meta-data from <https://oss.jfrog.org/artifactory/oss-snapshot-local/io/arrow-kt/arrow-mtl/0.11.0-SNAPSHOT/maven-metadata.xml>.
[2020-06-29T19:32:38.437Z] > Could not get resource '<https://oss.jfrog.org/artifactory/oss-snapshot-local/io/arrow-kt/arrow-mtl/0.11.0-SNAPSHOT/maven-metadata.xml>'.
[2020-06-29T19:32:38.437Z] > Could not GET '<https://www.jfrog.com/error?from=oss.jfrog.org&by=nginx-shared4c.gcoss-use1.jfrog.local>'. Received status code 403 from server: Forbidden
Oddly enough, if I visit one of those oss.jfrog.org urls directly, I’m able to download that metadata filetim
07/01/2020, 8:56 AMEither<A, List<Either<A, B>>
so I've created two extension functions to unpack it:
fun <L, R> List<Either<L, R>>.splitLeftAndRight(): Tuple2<List<L>, List<R>> {
val left = mutableListOf<L>()
val right = mutableListOf<R>()
forEach {
when (it) {
is Either.Left -> left += it.a
is Either.Right -> right += it.b
}
}
return Tuple2(left.toList(), right.toList())
}
fun <A, B, C> Either<A, List<Either<A, B>>>.flattenAndMap(f: (Tuple2<List<A>, List<B>>) -> C): Either<A, C> =
when (this) {
is Either.Left -> a.left()
is Either.Right -> {
f(b.splitLeftAndRight()).right()
}
}
And now in my comprehension becomes:
.map {
// something that returns Either<A, List<Either<A, B>>>
}
.flattenAndMap { (lefts, rights) ->
log.warn { "Filtering nested lefts: $lefts" }
rights
}
So my question here is, does this approach make sense, or is there something wrong with it/I've missed something in the FP toolbox that would make my life easier?
Thank you!than_
07/02/2020, 12:39 PMfun <V1, V2, ..., V22, E, R)validatedMapN(v1: Validated<E,V1>, v2: Validated<E,V2>, ..., v22: V22, sg: Semigroup<E>, f: (V1, V2, ..., V22)->R): Validated<E, R>
addamsson
07/05/2020, 12:04 PMmarc0der
07/07/2020, 3:36 PMcurry()
extension methods on functions of arity 2 in arrow-core:
https://github.com/arrow-kt/arrow-core/blob/master/arrow-core-data/src/main/kotlin/arrow/core/predef.kt#L5Tristan MARIE
07/08/2020, 2:00 PMTristan MARIE
07/08/2020, 2:00 PMraulraja
07/08/2020, 2:32 PMsimon.vergauwen
07/08/2020, 3:16 PMA?
to Either<E, A>
. Where you have to supply a fallback E
value. You can find it as rightIfNull
there are runnable examples on the website.
https://arrow-kt.io/docs/0.10/apidocs/arrow-core-data/arrow.core/-either/#syntaxfteychene
07/08/2020, 3:19 PMpost("...") {
val dayToAdd: Either<ServerError, String> = ...
val year: Either<ServerError, Int> = ...
val month: Either<ServerError, String> = ...
dayToAdd.product(year).product(month)
.flatMap{ (dayToAdd, year, month) ->
PlanningService.getOrCreate(year, month)
.map { planning -> PlanningService.addDayToPlanning(planning, dayToAdd) }
}
.fold(
{ /* Respond Error */ println(it) },
{ /* Respond */ println("Success") }
)
}
If i'm wrong please let me know 😅