Skip to content

Improve dataflow flatmap and dataflow map #45

Open
@AndreVanDelft

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.

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