https://kotlinlang.org logo
#stdlib
Title
# stdlib
a

asad.awadia

04/16/2019, 12:20 PM
Any ideas on what infix functions can be useful in a rest api? Looking for ideas to codify
c

Czar

04/16/2019, 12:57 PM
I feel that infix functions should only be present in a DSL, like test assertions or rule engine, etc.
1
a

asad.awadia

04/16/2019, 4:22 PM
So like don’t use it in regular code?
c

Czar

04/16/2019, 4:40 PM
Well, that's my take on it, some would probably disagree.
r

r4zzz4k

04/16/2019, 5:02 PM
In some cases infix functions are more readable than factory methods. For example, I'm using these:
Copy code
val point1 = Point(1, 3)
val point2 = Point(7, 8)
val size: Size(2, 2)
// ...
val rect1 = point1 rectTo point2
val rect2 = point1 rectOfSize size
val rect3 = point2 centeredRectOfSize size
c

Czar

04/16/2019, 6:03 PM
Yup - as I've said - DSL 😉
r

r4zzz4k

04/16/2019, 6:04 PM
Well, I'm not entirely sure I'd call that DSL, but I see your point 🙂
c

Czar

04/16/2019, 6:22 PM
yeah, definitions are quite blurry 🙂 there is at least one infix function I'm using all the time in "normal" code:
to
My main point is, code is code, don't try to make it into something else just for the sake of it. Sometimes it is warranted, but often - it is not.
👍 2