`to` is a factory function for pairs, there's no i...
# getting-started
k
to
is a factory function for pairs, there's no inherent connection to maps.
s
Yeah, i was wondering why isn't that decided to be an operator public infix fun <A, B> A.to(that: B): Pair<A, B> = Pair(this, that)
Is it just because overloading doesn't make sense?
k
I'm not sure what you mean, how could this be an operator?
It's also better language design, now there's no special case for this.
s
like operator fun <T : Comparable<T> > T.rangeTo( that : T) : ClosedRange<T>
for call site usage of start..end
n
well that could be made as a infix function too butthen you would need to write
Copy code
1 `..` 10
looks funny i guess
s
@Nikky didn't mean infix, just the operator
was trying to get my head around as to when to make an extension an operator and when not to
n
and that goes back to why
to
is not a operator.. because it does not need to be
s
Got it, basically usage determines
k
Well you have no choice, you can't add new operators.
n
well generally when the operation matches what you are doing.. there is super hard to read scala code that goes hame with operator overloading
s
oh that too
k
But for the language designers it's about finding a balance I guess. Also so they couldn't reuse
..
for pairs, since then 0..5 should be a pair too.
👍 1
n
so only use the operators when it makes sense and will keep making sense
but you can go ham with extension and infix functions, those are easier to understand in general, but there too is a balance between extremlyDescriptivename and super short and confusing names
String.fix() = ... <- wtf would that do
well i hope i got my points across
s
makes sense