raulraja
01/27/2021, 11:22 AMeither {
val a = funThatReturnsEither().bind()
val b = eitherValue.bind()
}
2️⃣ invoke
either {
val a = funThatReturnsEither().invoke() //explicit
val b = funThatReturnsEither()() //implicit
val c = eitherValue()
}
3️⃣ not
either {
val a = !funThatReturnsEither()
val b = !eitherValue
}
4️⃣ other and opinions: (reply in a thread to this message)thanerian
01/27/2021, 11:30 AMCLOVIS
01/27/2021, 11:32 AM!
notation might hurt readability. I liked the component1
but you explained why that's not possible, too bad. bind
is at least very easy to understand, but it's also not ‘beautiful'...raulraja
01/27/2021, 11:32 AMEither<Error, Boolean>
since you’re not negating the boolean value in !eitherValueContainingBoolean
instead you are obtaining the boolean value you i’d require !!
to negate.raulraja
01/27/2021, 11:35 AMnot
because the edge case is rarely seen and !
makes me easily see where all effects are firing without the bind
boilerplate but I agree that bind is more explicit. My concern with bind is that inside a computation block is gonna show up in pretty much every line and adds quite a bit of noise to what the code is actually doing.stojan
01/27/2021, 11:41 AMval x by myFunction()
still an option? (the for comprehension plug in syntax)raulraja
01/27/2021, 11:42 AMby
option has two issues. delegation support for suspension and it requires always to define a new val
and name it, even when you don’t care about the result.Jorge Castillo
01/27/2021, 11:42 AMsimon.vergauwen
01/27/2021, 11:42 AMval _ by something()
raulraja
01/27/2021, 11:43 AM!f + !g
Satyam Agarwal
01/27/2021, 11:45 AMaballano
01/27/2021, 11:45 AMJorge Castillo
01/27/2021, 11:46 AMaballano
01/27/2021, 11:47 AMaballano
01/27/2021, 11:48 AMraulraja
01/27/2021, 11:48 AMby
could be added easily once suspension support is working on main Kotlin and not just IR on delegated suspended properties https://youtrack.jetbrains.com/issue/KT-20414CLOVIS
01/27/2021, 11:49 AMbind
as something else, to create a syntax that doesn't already exist? Even if it's rare that !
is actually used for negation, it's still a syntax that's deeply linked with it, and you can't know if it's negation or bind
without reading very deeply into the code (especially if you have an effect that returns a boolean)
One solution could be to have an IDEA plugin that displays a different unicode character that doesn't exist in the Kotlin language for this specific character, so you would type !
but it would show up as something else (obviously there needs to be an option to disable it if you prefer to read the real code).
In the same way that IntelliJ can ‘render' documentation, or simplify functions by putting them in a single line, you would see something like :
either {
val a = ▷funThatReturnsEither()
▷a + ▷Right(5)
}
The code would use !, but if the IDE could put this as a ‘hint', there would never be any ambiguity (since the IDE knows without a doubt which it is)raulraja
01/27/2021, 11:52 AMraulraja
01/27/2021, 11:53 AMCLOVIS
01/27/2021, 11:54 AMf1 ◯ f2
for composition, it really helps readability when it's not overused).CLOVIS
01/27/2021, 11:54 AMraulraja
01/27/2021, 11:55 AMfun <A> A.`◯`(other: A): A = TODO()
tginiotis
01/27/2021, 11:56 AM!
notation for monad operators looks very alien to the rest of the language. It used to be strictly negation and anyone new to the codebase, Arrow or both would likely be lost on what it means. I think the !
has a really strong meaning that will just cause confusion.
• The invoke
, ()
notation looks best, because it indicates to me that some sort of processing will be happening, a function invocation. A monad bound to the context in this case.
• The bind()
notation is meh, but still better than negation.raulraja
01/27/2021, 11:58 AMEither
and you are in an either
block then you have these double invokes
funThatReturnsEither()()
tginiotis
01/27/2021, 12:06 PMraulraja
01/27/2021, 12:07 PMtginiotis
01/27/2021, 12:25 PMalbertosh
01/27/2021, 1:15 PMbind
explicitly implies that you’re “extracting” the value from the monad so you can operate over it. It makes it easier for non-FP developers to follow your code (maybe you don’t understand how, but you know that Either<A,B>.bind()
gives you a B
)
2. invoke
has a similar effect as bind
, the problem would be, again, for non-FP devs to understand what “executing a monad is”. Also, non-FP devs are not so used to see function()()
3. I really like !
. It’s simple & concise. Major drawback, as you mention, is the usecase with booleans. Plus maybe readability issues?
Is it feasible to have, for example, bind
as the “main” operator and both invoke
and not
as inline functions that just invoke bind
?stojan
01/27/2021, 1:31 PMJorge Castillo
01/27/2021, 1:31 PMraulraja
01/27/2021, 2:25 PMCuan
01/27/2021, 9:17 PM!!
to negate a boolean
• !!
is already used in Kotlin to convert to a non-nullable typeaballano
01/28/2021, 1:07 AMScott Christopher
01/28/2021, 7:10 AMbind()
was to keep the method explicit for now, knowing that syntactic sugar may be available as compiler plugins in the future.