Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structural based fx DSL #23

Open
raulraja opened this issue Jun 5, 2019 · 0 comments
Open

Structural based fx DSL #23

raulraja opened this issue Jun 5, 2019 · 0 comments
Assignees

Comments

@raulraja
Copy link
Member

raulraja commented Jun 5, 2019

We can leverage compiler plugins to automatically rewrite imperative flows that use Kind<F, A>.bind() into rewrites that are simply flatMap based. This will free us from the stack labels machinery which currently uses reflection, ties us to the JVM and it's slow.

An implementation may do the following:

  • Find all declarations of fx blocks
  • Digg into the function ordered KtCallExpression and find all suspend calls that use !
  • If there are dependencies between the order of operations Rewrite the function body so each ordered ! it translates into a flatMap chain where the remaining expressions below are nested ending in a final map.
fx {
  val a = !fa
  val c = !fb(a)
  c + 1
}

becomes:

fa.flatMap { a -> 
  fb(a) 
}.map { c ->
  c + 1
}

This is similar as to how scala for comprehensions work and it would free us from being dependent on suspension and in general the coroutine limitations around fx

@raulraja raulraja self-assigned this Sep 30, 2019
@raulraja raulraja transferred this issue from arrow-kt/arrow-meta-prototype Sep 30, 2019
@rachelcarmena rachelcarmena transferred this issue from arrow-kt/arrow Oct 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant