A question about the `operator fun invoke` in `Eit...
# arrow
k
A question about the
operator fun invoke
in `Either.Left`: why is it there? It looks like a constructor but I can't think of a case where the behavior would be different from just making the constructor public instead. It made sense for kategory when
Either.Left
had two type parameters so you wouldn't have to specify the
Nothing
type explicitly (https://github.com/JcMinarro/kategory/blob/master/kategory-core/src/main/kotlin/kategory/data/Either.kt#L125), but why does arrow have it too? (https://github.com/arrow-kt/arrow/blob/master/modules/core/arrow-core-data/src/main/kotlin/arrow/core/Either.kt#L818). For that matter, why did
Either.Left
ever have two type parameters in kategory?
r
As Kotlin inference capabilities evolved so did the Either constructors
Initial encodings of Option and Either in Kategory were proof of concepts the Android spanish community put together as they were learning FP.
I did many talks in Spain before that when they all thought I and a couple of other guys were crazy 😅
But from all the collaboration and good times and parties in many places Kategory was born
Regarding the operator it may be a leftover but maybe ask the git blame author (hope it's not me)
k
Category theory themed parties, sounds great 😄
So what specifically changed? Was a declaration like
class Left<A>(val a: A): Either<A, Nothing>
ever not allowed in Kotlin?
r
If I recall right we had issues in pattern matching having to specify both types and poor inference in the left and right extensions
Parties with heavy drinking and 🌬️ specifically. It all started in the Freakend
A weekend conf in Spain where talks run up to 3 am and longer and it's a never ending party. You know. Spain.
k
Sounds like I need to visit sometime!
I followed the blame trail and it indeed ends up in kategory legacy when
Either.Left
still had two type parameters.
p
it’s there for inference purposes, or at least it may have been at some point
Nothing
, which I cannot even remember if it’s what we use these days, used to be inferred poorly in kotlin 1.0
so you had to put a function in the middle to make it work
k
(At one point
Left
even had a weird dummy
Unit
variable: https://github.com/arrow-kt/arrow/commit/32e115dc33a0b6dfa5d4fa036d7b7c0042658f83)
Makes sense, thanks for all the replies! I asked the same question two years ago about kategory but then I had just learned about
Nothing
which was scary 🙂
p
Unit is a common trick when you have a function and a constructor with the same name