-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add bare Kotlin type overloads for expression functions #196
feat: Add bare Kotlin type overloads for expression functions #196
Conversation
...ompose-expressions/src/commonMain/kotlin/dev/sargunv/maplibrecompose/expressions/dsl/math.kt
Show resolved
Hide resolved
...e-expressions/src/commonMain/kotlin/dev/sargunv/maplibrecompose/expressions/dsl/variables.kt
Show resolved
Hide resolved
...expressions/src/commonMain/kotlin/dev/sargunv/maplibrecompose/expressions/dsl/collections.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems to be missing for
- both
switch
(i.e. the fallback, but also secondary constructors for thecase
andcondition
- all the comparison functions
within
By the way, why is the constructor of Case
and Condition
private and then there is a function that is basically a constructor for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just stylistic preference. I prefer to think of the expressions DSL as regular functions, and short-lived objects like Case
and Condition
are implementation details to get the typing and syntax right.
Additionally, Dokka shows documentation for functions on a different page from types, and this keeps documentation for the construct and also the branches on the same page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and similar to math, overloads for generic stops means writing a whole lot of overloads for many different types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true... , but using literals for these constructs is pretty much the default case for these constructs.
...ose-expressions/src/commonMain/kotlin/dev/sargunv/maplibrecompose/expressions/dsl/feature.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all overloads with bare types are missing for the math functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For math operators, it felt odd to me to have different types on two sides of the operator. Maybe it's okay though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also for anything related to numbers with units, we'd write a lot of overloads for bare types (no unit, Dp, TextUnit, Duration, maybe Meters in the future). Seems not worth it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, not sure, IIRC the Android MapLIbre SDK does that. (For Floats only, of course)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The stops for the interpolate expressions and step expressions don't have bare Kotlin overloads.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With current typing (the Pair
), either all stops will have to be Kotlin values, or all stops Expressions. Thoughts on doing something like case
and condition
(maybe stop
?) so we can use different overloads on each stop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is rather the default / usual case that no expressions are used, so the overload that doesn't allow any expressions for the stops would I think be the most used one.
Having data classes for step
and interpolate
i.e. stop(...)
sounds fine to me, too. It's only marginally less convenient/more verbose than the to
(and anyway, that is just a normal infix function, you could name the function that creates a Stop
also like that.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be wary of shadowing to
so would want a different infix name, or just stop()
like the others.
It's true that most stops/case/condition would be const
, but also interpolate/switch is already a pretty big, verbose, construct, and so adding one const per stop doesn't hurt readability much (at least to my eye).
Compared to get
and has
which were small enough that the const dwarfed the get/has and made it confusing to read.
it wouldn't really be shorter, and would be less transparemt
El 27 de diciembre de 2024 16:55:29 CET, Sargun Vohra ***@***.***> escribió:
…
@sargunv commented on this pull request.
> @@ -16,6 +16,11 @@ public operator fun <T : ExpressionValue> Expression<ListValue<T>>.get(
index: Expression<IntValue>
): Expression<T> = FunctionCall.of("at", index, this).cast()
+/** Returns the item at [index]. */
***@***.***("getAt")
+public operator fun <T : ExpressionValue> Expression<ListValue<T>>.get(index: Int): Expression<T> =
+ get(const(index))
+
/** Returns whether this list contains the [item]. */
@JvmName("containsList")
public fun <T : ExpressionValue> Expression<ListValue<T>>.contains(
Adding an overload for List<String> sounds good to me if it doesn't shadow the regular Kotlin `contains`.
If it does shadow, well I think we already have `const(listOf())` so it's not too bad. Should there be a `constList(varargs)`?
--
Reply to this email directly or view it on GitHub:
#196 (comment)
You are receiving this because your review was requested.
Message ID: ***@***.***>
|
closes #193