[<<][erlang][>>][..]
Fri Sep 2 09:27:59 EDT 2016

Sink vs. Fold

I've been using two interfaces to represent sequences.  These grew out
of actual used:

- impure sink-parameterized generators:

  a sequence is a generator parameterized by a function (procedure)
  that takes {data,Data} or eof values.

- pure left fold:

  a sequence is a function that takes an initial state and a left fold
  body, producing a final state.


A fold can be turned into a sink-parameterized generator through
applying the sink in the fold's iteration body.

A sink-parameterized generator can be turned into a fold by employing
a process to convert the pushing call to sink into a pulling receive.


The decision to use either is driven by representing the sequence as

 - a push: the sink is abstracts "!"
 - a pull: the fold abstracts a loop over "receive"


EDIT:

- When in doubt, express the pattern as left+right fold and use
  fold:iterate to generalize into list, sink-parameterized generator.

- If the data is always sent somewhere, it's ok to keep wrapping sinks
  until they can be merried to a fold somewhere.
  



[Reply][About]
[<<][erlang][>>][..]