Hi. Is it possible to use suspend function for mod...
# arrow
a
Hi. Is it possible to use suspend function for modify inside Arrow optic? Like:
Copy code
MyType.foo.bar.every.baz.modify(obj) { someSuspendFun(it) }
t
currently, unfortunately no. The
modify
would have to be
inline
. But I have a feeling @simon.vergauwen could have some some near future good news regarding this topic 🙂
s
Currently, this is indeed not possible since
interface
cannot contain any
inline
functions (this is because there no code to inline, since it's dispatched to a runtime implementation).
It's possible however to add, extension functions to the interface that allow inlining. i.e.
Copy code
inline fun <S, A> Lens<S, A>.modifySuspend(source: S, f: (A) -> A): S {
  val focus = get(source)
  f(focus)
  return set(source, focus)
}
This could be solved by moving to
class
, and revering the current hierarchy to not use inheritance for auto-conversion between optics.
If interested, we could move this to a ticket to discuss further there.
a
@simon.vergauwen as it was single use case only the problem was just solved without optics. However for the future it would be nice to have some solution that works with suspend (and I guess with other "code coloring" as well but idk) So yeah, adding this discussion to some ticket would be great :)