what i'm doing is just reading the arguments given...
# arrow
t
what i'm doing is just reading the arguments given from ktor (which are nullable string), use them to retrieve a planning and add to it the PlanningDay given by the user in the request
r
Hi Meimei, no point in using Option there if you already have a way to extract args as nullable types
☝️ 1
s
There are also constructors to go straight from
A?
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/#syntax
f
Hi 👋 Agree with not using option For the rest of the code I would translate to something like that if the errors types aligns (that seems to be the case from your snippet)
Copy code
post("...") {
    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 😅
☝️ 1