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

Improve dataflow flatmap and dataflow map #45

Open
AndreVanDelft opened this issue May 18, 2016 · 1 comment
Open

Improve dataflow flatmap and dataflow map #45

AndreVanDelft opened this issue May 18, 2016 · 1 comment

Comments

@AndreVanDelft
Copy link
Contributor

AndreVanDelft commented May 18, 2016

There are essentially 3 variations for normal dataflow, AKA dataflow-flatmap:

~~>
~/~>
~~> +~/~>

IMO these should be implemented separately, using do-then, do-else, do-then-else:

def _dataflow_then(s: Script[Any], t: Any => Script[Any], e: Throwable => Script[Any]): Script[Any] = {
  var s_node: N_call[Any] = null
  ([do @{s_node = there.asInstanceOf[N_call[Any]]}: s then t(s_node.$success)^])
}

def _dataflow_else(s: Script[Any], t: Any => Script[Any], e: Throwable => Script[Any]): Script[Any] = {
  var s_node: N_call[Any] = null
  ([do @{s_node = there.asInstanceOf[N_call[Any]]}: s else e(s_node.$failure)^])
}

def _dataflow_then_else(s: Script[Any], t: Any => Script[Any], e: Throwable => Script[Any]): Script[Any] = {
  var s_node: N_call[Any] = null
  ([do @{s_node = there.asInstanceOf[N_call[Any]]}: s then t(s_node.$success)^ 
                                                      else e(s_node.$failure)^])
}

Something similar holds for dataflow-map:

def _dataflow_then_map(s: Script[Any],  f: T => Any): Script[Any] = {
  var s_node: N_call[Any] = null
  ([do @{s_node = there.asInstanceOf[N_call[Any]]}: s then ^let f(s_node.$success) ])
}

def _dataflow_else_map(s: Script[Any],  g: Throwable => Any): Script[Any] = {
  var s_node: N_call[Any] = null
  ([do @{s_node = there.asInstanceOf[N_call[Any]]}: s else ^let g(s_node.$failure) ])
}

def _dataflow_then_else_map(s: Script[Any],  f: T => Any, g: Throwable => Any): Script[Any] = {
  var s_node: N_call[Any] = null
  ([do @{s_node = there.asInstanceOf[N_call[Any]]}: s then ^let f(s_node.$success)
                                                      else ^let g(s_node.$failure) ])
}

Probably the latter three may be implemented more efficiently using dedicated do-thenMap, do-elseMap, do-thenMap-elseMap nodes.
Also the parser should start to accept syntax for the else-parts.

@AndreVanDelft
Copy link
Contributor Author

AndreVanDelft commented May 24, 2016

Another thing: to pass the earlier mentioned Pastiche test, there should also be a dataflow operator that transfers both the success data and the failure exception, packed in the Try:

x ~+/~> y
x ~+/~(p:Try[T])~~> y

This requires another new construct:

do x finally y

which is in ACP terms equivalent to

do x then y else y

The difference in Scala terms is that there is only one occurrence of y.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant