seetha
01/12/2022, 7:50 PMseetha
01/12/2022, 8:03 PMseetha
01/14/2022, 6:53 PMkotlin-maven-plugin
needs any modifications or configurations here?Norbi
01/15/2022, 9:17 AMplugins {
...
id("com.google.devtools.ksp") version "1.6.10-1.0.2"
}
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
...
api("io.arrow-kt:arrow-optics:1.0.1")
}
...
}
}
dependencies {
ksp("io.arrow-kt:arrow-optics-ksp-plugin:1.0.2-alpha.28")
}
Example.kt
...
@optics
data class Example(val p: String) {
companion object
}
But no files are generated, the build\generated\xxxMain
folders are created but remain empty.
During the build process the corresponding tasks are executed (and I see a warning):
...
The 'ksp' configuration is deprecated in Kotlin Multiplatform projects. Please use target-specific configurations like 'kspJvm' instead.
...
Task ... kspKotlinJs UP-TO-DATE
...
Task ... kspKotlinMetadata UP-TO-DATE
...
Task ... kspKotlinJvm UP-TO-DATE
...
Do you have any idea what piece is missing? Thanks.João Gabriel Zó
01/16/2022, 5:36 PMPhilipp Mayer
01/17/2022, 5:25 PMEither
of type <List<Error>, Success>>
, how could I collect both of their lefts (if both are left).
My setup looks like this:
import arrow.core.Either
data class Error(val message: String)
data class Success(val data: Int)
data class SuccessSum(val success1: Success?, val success2: Success?)
fun myFunction(): Either<List<Error>, SuccessSum> {
val responseA = someNetworkCall()
val responseB = someNetworkCall()
return TODO()
}
fun someNetworkCall(aGivenParameter: Int = 1): Either<List<Error>, Success> {
TODO()
}
and I have the following possibilities regarding my return type:
it can either be:
• a list of errors originating from the first response
• a list of errors originating from the second response
• a list of errors originating from both responses
• SuccessSum
, my happy path
Is there any way to check if both eithers are null and if they are, merge their left values together into one list?
My happy path would then look like that:
fun myFunction(): Either<List<Error>, SuccessSum> {
val responseA = someNetworkCall()
val responseB = someNetworkCall()
/* Guard Clause checking for lefts here */
return SuccessSum(
success1 = responseA.orNull(),
success2 = responseB.orNull()
)
}
That’s at least my initial idea. I guess Validated
could be a better option but I didn’t look into it yet.
Thanks in advance! 🙂Luke
01/21/2022, 8:33 PMEither
only if it is a Left
? I have a state that I want to modify its Either
variable, something like:
data class State(val either: Either<Error, Something>)
And I want something like this:
State.either./*focusIfLeft()*/.modify(state) { left: Left<Error> -> Something().right() }
Is there a way to do that already or a need to define my own extension?Milse113
01/27/2022, 6:08 PMTower Guidev2
01/28/2022, 11:37 AMBart Kleijngeld
01/29/2022, 1:12 PMjeff
01/29/2022, 10:08 PM"io.arrow-kt:arrow-optics-ksp-plugin:1.0.2-alpha.42"
) seems to have a bug: if I put @optics on a data class with 3 or fewer fields it generates code with first
, second
, third
which is great because arrow.core.Tuple3 has those fields.a
, b
, c
, d
which fails because arrow..core.Tuple4 does not have those fields (it has first
through fourth
) -- is this a known issue?Tower Guidev2
01/31/2022, 8:29 AMSrki Rakic
02/01/2022, 12:44 AMValidated
instead require
for validation when constructing an object.
class Probability private constructor(val value: Double) {
companion object {
fun create(value: Double) =
if (value > 0.00 && value < 1.00) Probability(value).valid()
else ValidationError.ProbabilityOutOfBounds("Probability must be between 0.00 and 1.00").invalid()
}
}
I'm struggling to find the best way to structure it in a given context. Typical use case for `Probability`:
val fsmIdentifiers =
listOf(
FsmIdentifier(
key = "first",
mProbability = Probability(0.95),
uProbability = Probability(0.1),
compare = ::jaroWinklerDistance
),
FsmIdentifier(
key = "last",
mProbability = Probability(0.99),
uProbability = Probability(0.01),
compare = ::jaroWinklerDistance
),
FsmIdentifier(
key = "middle",
mProbability = Probability(0.90),
uProbability = Probability(0.1),
compare = ::jaroWinklerDistance
),
......
)
As you see, the Probability
is created as part of the FsmIdentifier
(and other similar identifiers). Any suggestion on how to handle the creation with Validated
in this context cleanly, without making the code look overwhelmingly verbose?Łukasz Gendek
02/01/2022, 10:50 AMthan_
02/01/2022, 11:05 AM@JvmInline
@Serializable
value class Email(val value: String) {
init {
pre(value.matches(emailRegex)){ "Must be a valid email" }
}
override fun toString(): String = value
}
which of course won't work since
You can only create Boolean expressions using basic arithmetic operations (addition, subtraction, …), comparisons, and simple Boolean operations (and, or, not). In particular, you cannot define a Boolean function and use it in a condition;
Will there be possibility of regex matching in the future or should we use a runtime solution?Nathan Bedell
02/01/2022, 4:34 PMseetha
02/02/2022, 3:12 PMretry
function available in Schedule
on version 1.0.0
?
We are stuck at version 1.0.0
because of this issue and I am not finding retry
Alejandro Serrano Mena
02/02/2022, 6:21 PMmikehearn
02/02/2022, 9:20 PMmikehearn
02/02/2022, 9:43 PMreturn z.post({ it > 0 }) { "greater than 0" }
where the string is in a block, rather than a parameter. It seems less visually noisy to write as z.post("greater than zero") { it > 0 }
- yeah it's different to require, but it seems to make more senseŁukasz Gendek
02/03/2022, 11:24 AMPeter
02/03/2022, 4:56 PMArrow-Analysis
… it’s early here but am i being dense with this error? 😅Gavin Ray
02/03/2022, 5:50 PMArrow-Analysis
in a separate compilation task from regular?
The reason I ask is because of potentially increased compile times, which I assume would add up if you're frequently re-compiling your code to test. (Maybe this is not the case though)Bart Kleijngeld
02/08/2022, 10:33 AMalightgoesout
02/08/2022, 4:40 PMEither<E, A>
is not used? In particular, this would be great in an either { … }
block when calling IO functions that return Either<Error, Unit>
to prevent forgetting to call bind()
on the result to propagate the error.Benoît
02/09/2022, 1:38 PMdimsuz
02/10/2022, 2:35 PMset
has type A -> S -> T
, but actual set
implementations seem to have it reversed: S -> A -> T
.
Screenshots are from: api docs
Similarly main page of Arrow Optics mentions set: A -> S -> S
, but then has an example of playerLens.set(player, health)
. Am I reading this wrong or is this a little bug?sam
02/10/2022, 7:52 PMjulian
02/12/2022, 4:18 PMcarbaj0
02/13/2022, 5:51 AMcarbaj0
02/13/2022, 5:51 AMEitherEffect<Error,A>
instead of EitherEffect<Error,*>
would be a right solution?raulraja
02/13/2022, 11:57 AMcarbaj0
02/13/2022, 3:36 PMsimon.vergauwen
02/17/2022, 10:20 AMSatyam Agarwal
02/17/2022, 10:51 AMsimon.vergauwen
02/17/2022, 11:54 AMBut limitation that we cant pass multiple parameters in with makes the start of program nasty.This is planned afaik, but it's not been implemented in the current preview.
it brings repetition to all the functions using itThere is some repetition, yes, but I don't see this as a bad thing perse. You only need to add the receivers the function actually uses, so it's similar to effect handlers or final tagless in Haskell/Scala.
Tower Guidev2
02/18/2022, 8:42 AMraulraja
02/18/2022, 9:55 AM-Xcontext-receivers
and also the same in the IDE Kotlin settings, for some reason in my case the IDE its not picking the setting from Gradle.Tower Guidev2
02/18/2022, 10:50 AMsimon.vergauwen
02/20/2022, 9:45 AM2021.3.2
.Tower Guidev2
02/21/2022, 8:23 AMIntelliJ IDEA 2021.3.2 (Community Edition)
Build #IC-213.6777.52, built on January 28, 2022
and Kotlin plugin version...simon.vergauwen
02/21/2022, 9:26 AM-Xcontext-receivers
flag.
Can you try the repo I linked in my blogpost, that is working for me with the setup you're using. https://github.com/nomisRev/context-receivers-blog