```Either.fx() { val (x) = someLeftValue() 10 ...
# arrow
a
Copy code
Either.fx() {
  val (x) = someLeftValue()
  10
} // Left propagates

Either.fx() {
  someLeftValue()
  10
} // Either.Right(10)
j
No, sadly not. You need to call either
bind
or one of its aliases
!
component1()
to bind something in an
fx
. I would like it to be like haskell do-blocks where such things bind automatically but that is not quite possible afaik. Maybe this will change with arrow-meta because this causes a lot of confusion imo. @raulraja Can comprehensions in meta automatically bind anything that is not an assignment?
Copy code
fx {
  // binds
  val x by action
  // also binds
  action
  // does not bind
  val x = action
}
Something along those lines? I think not binding the second thing there will be really confusing.
Oh before I forget, @aeruhxi if you end up not using the value returned by
component1
or if you bind something like a boolean with
!
the compiler will sometimes do funny stuff with it (like trying to "optimize") and that can break comprehensions. So in those cases sticking to
bind
is best
a
I see, thanks. It seems:
val (_) = someLeftValue()
doesn't bind either. So, I'll stick to
bind()
for now.
j
Yup that is the compiler "optimizing". Here is an issue that documents this: https://github.com/arrow-kt/arrow/issues/1754
k
They’re actually going to deprecate ! and () for this reason. bind() will be the canonical and only option. (See @Jannis’s link for a comment by Paco about this). Actually it seems it’s all going to be mooted by Arrow Meta, which should be coming up in the next few months I think.
r
@Jannis and others in this thread. Comprehensions in meta won't allow binding or destructuring in place because in those cases a rewrite to flatMap is not possible in all cases and additionally not binding to a variable in a comprehension allows for local substitution not possible in non-commutative monads like streams and lists.
We used to have an example of that at some point in the fx docs for list, on my phone now but if anyone is interested I'll dig it up when I get to a comp
j
Isn't this example:
Copy code
fx {
  // binds
  val x by action
  // also binds
  action
  // does not bind
  val x = action
  <...>
}
Equal to the following haskell code:
Copy code
do
  // binds
  x <- action
  // also binds
  action
  // does not bind
  let x = action
  <...>
So why would a desugaring not be possible if that works fine for
do
blocks?
r
Can you bind in haskell in the same line multiple times?
That was the limitation I saw when binding happens inside an expression and that expression has multiple binds
j
no you can't but that isn't really what I think would be important. Can you even do that with meta
by
- syntax? Either way binding only for effects (outside of assignments and expressions) should be doable right?
r
Yes, we can make it whatever we want. At the moment it just looks for properties with by delegation
If you wanna hack on it I'll be happy to help 🙂
j
Yes, we can make it whatever we want
I definitly need to play around with that sometime^^
If you wanna hack on it I'll be happy to help 🙂
I do, but not now or the next 1-2 weeks, too much going on, so I'll add me a reminder, thanks 🙂