George
11/16/2022, 2:07 PMorThrow
or it's ok to omit it? For example:
private val CspAccount.retrieveAuthenticatedDevice: CspDevice
get() = this.authenticatedDevice.getOrElse {
throw WebApplicationException(
"Authenticated device for account: ${this.number} was not found",
Response.Status.UNAUTHORIZED
)
}
It would be better if i renamed it to getAutheticatedDeviceOrThrow()? Thanks in advance for any answers !czuckie
11/28/2022, 11:39 AMlanguage-support
as in adding things the language doesn't offer but perhaps could.Sam Stone
12/09/2022, 4:49 AMfoos.find { it.id == id }
) so this is nice sugar for me (used like foos.findBy(id) { it.id }
):
inline fun <T, R> Iterable<T>.findBy(key: R, selector: (T) -> R): T? = find { selector(it) == key }
Maybe rename to just find
? findIn
?Vitor Hugo Schwaab
01/14/2023, 12:21 AMSam
01/20/2023, 11:42 AMfold
, but the operation
is allowed to return null
, in which case the whole thing exits early with a null
return value.
private inline fun <T, R> Iterable<T>.fold2(initial: R, operation: (acc: R, T) -> R?): R? =
fold<T, R?>(initial) { acc, element -> operation(acc ?: return null, element) }
Stylianos Gakis
02/03/2023, 6:42 PMinterface AuthenticationListener {
suspend fun loggedIn()
suspend fun loggedOut()
}
This will be in a common module without more dependencies, and whichever module is interested can provide implementations of this interface to do stuff that it may need to do on login or logout.
Then there should be some class which is called ??? Letās just say AuthenticationEventDispatcher
for now
class AuthenticationEventDispatcher(
authenticationListeners: Set<AuthenticationListener>, // injected
applicationScope: ApplicationScope,
coroutineContext: CoroutineContext,
) {
private val authEvents = Channel<AuthenticationEvent>(Channel.UNLIMITED)
init {
applicationScope.launch(coroutineContext) {
authEvents.consumeAsFlow()
.collect { event ->
authenticationListeners.map { authenticationListener ->
async { when (event) { LOGGED_IN -> authenticationListener.loggedIn(); LOGGED_OUT -> authenticationListener.loggedOut() } }
}.awaitAll()
}
}
}
fun loggedIn() { authEvents.trySend(LOGGED_IN) }
fun loggedOut() { authEvents.trySend(LOGGED_OUT) }
private enum class AuthenticationEvent { LOGGED_IN, LOGGED_OUT }
}
Which should just take these events and inform all the AuthenticationListener instances to do whatever it is that theyāre gonna do (One example is that I want to get a member ID when logging in from the backend and save it, but this only works after having logged in first)
So with all this context, how would you better name āAuthenticationEventDispatcherā or even the āAuthenticationListenerā which I am also not happy about?Peter Mandeljc
02/07/2023, 10:23 AMFlow<Boolean>
with "is". E.g. val isVisible: Flow<Boolean>
?thanh
02/14/2023, 12:47 PMfun Set<A>nonEmptyIntersection(other: Set<A>) = this.intersect(other).nonEmty()
?pardom
02/21/2023, 8:40 PMdoThing()
⦠doThingAsync()
⦠doThingSuspending()
⦠doThingSuspended()
⦠etc?mbonnin
02/27/2023, 4:51 PMJSON
and not Json
, right? I've been using Json
everywhere but I think I'm wrong?Kshitij Patil
03/11/2023, 1:54 PMBuilder
pattern. You simply have one method Foo.build(param)
in the class interface which gives you the instance. Such classes use some other builder hierarchy by feeding received configurations in param
and gives you concrete instance, IE, abstracting away builder logic.
For instance, I have a custom notification builder class which is using NotificationCompat.Builder()
internally and giving Notification
instance on invocation.Tower Guidev2
03/28/2023, 8:17 AMYoussef Shoaib [MOD]
04/25/2023, 5:52 AMVecX
types that are mutable vectors, and I'm struggling to find a name for a new read-only Vector type that they should implement. I'm thinking maybe ReadOnlyVecX
but it seems to be too long. The issue is that changing the name of VecX
to MutableVecX
would be a big change, especially considering that most Vec-based code would be using mutability, while the read-only versions likely will be used to specify that method parameters and results can't be modified.
I also thought maybe VecXVals
could be an apt name since the interface would really only define the `val`s required to represent that vector, but it still doesn't seem elegant enoughRyan Smith
05/21/2023, 4:08 PMMichael de Kaste
05/23/2023, 1:10 PMasdf asdf
05/24/2023, 3:06 AMPascalCase
for constants instead of SCREAMING_SNAKE
Landry Norris
06/21/2023, 9:52 PMMichael de Kaste
07/06/2023, 10:09 AMMatt Nelson
08/04/2023, 1:45 PMchanjungskim
08/05/2023, 1:50 AMRafal
08/08/2023, 6:55 AMPrimaryButton / SecondaryButton
instead of ButtonPrimary / ButtonSecondary
?Jacob Rhoda
09/21/2023, 7:53 PMkotlin.Unit
to disambiguate?Leon Linhart
12/19/2023, 12:26 PMID
in identifiers with š
±ļø Id
.
⢠Renamed 1ļøā£ NPCText
, PoI
(point of interest), and PvPGame
to 2ļøā£ NpcText
, Poi
, and PvpGame
respectively.
Thanks šlouiscad
02/06/2024, 4:25 PMdave08
02/18/2024, 12:12 PMdave08
02/18/2024, 12:13 PMKev
03/15/2024, 9:59 AMStylianos Gakis
04/09/2024, 3:32 PM@Composable
fun Foo(
modifier: Modifier = Modifier,
content: @Composable BoxScope.() -> Unit,
) {
Layout(content = { Box { content() }, modifier = modifier) { measurables, constraints ->
val placeable = measurables.first().measure(constraints)
layout(placeable.width, placeable.height) {}
}
}
How would you name this Layout function? šRobert Williams
06/03/2024, 2:26 PMmbonnin
02/10/2025, 1:39 PM