CLOVIS
04/16/2024, 12:26 PMKev
04/16/2024, 1:21 PMCLOVIS
04/16/2024, 1:22 PMRaise
is to be part of the signature.rocketraman
04/16/2024, 2:20 PMraulraja
04/16/2024, 4:00 PMCLOVIS
04/16/2024, 4:01 PMRaise
DSL to short-circuit when some data is invalid and you want to return an error to the user.CLOVIS
04/16/2024, 4:01 PMraulraja
04/16/2024, 4:35 PMpost<ProfilesResource.Follow> { follow ->
jwtAuth(jwtService) { (_, userId) ->
either {
userPersistence.followProfile(follow.username, userId)
val userFollowed = userPersistence.select(follow.username).bind()
ProfileWrapper(Profile(userFollowed.username, userFollowed.bio, userFollowed.image, true))
}
.respond(HttpStatusCode.OK)
}
}
Could probably look like:
post<ProfilesResource.Follow> { follow ->
jwtAuth(jwtService) { (_, userId) ->
userPersistence.followProfile(follow.username, userId)
val userFollowed = userPersistence.select(follow.username).bind()
Ok(ProfileWrapper(Profile(userFollowed.username, userFollowed.bio, userFollowed.image, true)))
}
}
or similar, including validation functions and other's. A redefinition of post
and similar operators from Ktor to include the Raise
context would eliminate the need for Either
wrapping/unwrapping and specialized extensions functions like https://github.com/nomisRev/ktor-arrow-example/blob/147b8642fbb2f8c351436ff213610b9472153334/src/main/kotlin/io/github/nomisrev/routes/error.kt#[…]4simon.vergauwen
04/22/2024, 6:36 AMRaise
without that concern but I imagine that's not how people will react when they see "Arrow" as a dependency..
Arrow Core will be extremely small, much smaller than Kotlin Std or KotlinX Coroutines and everyone has that on the classpath.
It depends the most on the goal of your library tbh @CLOVIS, and it's a tricky decision. I've split the core in a bit more pieces, for example "autoclose DSL" since I am going to use that in a bunch of libraries and now it's a 1 file library that probably will never change...
And I am doing the same for SuspendApp
I am going to make it depend on Resource
(file) and AutoClose
(file), and that'll turn into a "terminal signal coroutinescope library".
Depending on Raise
, or Either
is more controversial to something like that though.