Skip to content

Improve dataflow flatmap and dataflow map #45

Open

Description

@AndreVanDelft

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.

Activity

  1. AndreVanDelft commented on May 24, 2016

    @AndreVanDelft
    ContributorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions