Hi, when `infix` functions are useful ?
# getting-started
a
Hi, when
infix
functions are useful ?
h
For creating DSLs or when you want something like an operator function, but with a new name
For example
until
is an infix function in the standard library to create a `Range`: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.ranges/until.html
­čÖĆ 2
e
kotlin-stdlib has lots of infix functions: for pair (
to
), range (
until
,
downTo
,
step
), collection/array (
zip
,
union
,
subtract
,
intersect
,
contentEquals
,
contentDeepEquals
), comparator (
then
), bitwise (
and
,
or
,
xor
,
shl
,
shr
,
ushr
)
and lots of other libraries have infix functions (e.g. a good chunk of the MockK and Kluent DSLs)
a
@ephemient Yeah I know but in which cases should I set methods as infix ?