https://kotlinlang.org logo
#compose
Title
# compose
z

Zach Klippenstein (he/him) [MOD]

11/03/2023, 6:56 PM
Thinking about the transformation chaining API for BasicTextField2. Which one of these do you prefer (see thread)
1:
Copy code
inputTransformation = maxLengthInChars(6)
  .then(allCaps(Locale.current))
where you can define your own transformations as
Copy code
fun allCaps(…): InputTransformation = …
2:
Copy code
inputTransformation = InputTransformation
  .maxLengthInChars(6)
  .allCaps(Locale.current)
where you define your own transformations as
Copy code
fun InputTransformation.allCaps(…): InputTransformation =
  this.then(…)
22
2 is a copy of the
Modifier
style, and requires a bit more ceremony to write custom transformations but is cleaner to use. 1 is simpler to write custom transformations, but harder to discover (no auto-complete) and more verbose to use
The currently-shipping code defines transformations as extension on
InputTransformation.Companion
, which is kind of the worst. Forces you to write
InputTransformation.
before every one, even within the same chain.
a

annsofi

11/03/2023, 7:08 PM
I’d say 2 because discoverability is more important to me at least
👍🏻 1
👍🏾 1
👍 2
e

efemoney

11/03/2023, 7:50 PM
Same I agree with 2.
d

Dario Ahdoot

11/03/2023, 8:35 PM
Same. 2
z

Zach Klippenstein (he/him) [MOD]

11/03/2023, 8:41 PM
Wow alright it’s tight but I think 2 is just slightly ahead
😂 14
s

saket

11/08/2023, 12:23 AM
I was thinking of voting for
1
because the chaining of transformations with
then()
makes it clear that they're applied in order, but I immediately remembered that
2
matches how we think of reactive operators and modifiers