Skip to content

Conversation

@thekid
Copy link
Member

@thekid thekid commented May 1, 2016

A processing function can handle the processing of elements passed to it in the following ways:

  1. Do something with and pass it on down the chain, just like peek()
  2. Do something with and return a result, just like map()
  3. Decide not to pass it on, just like filter()
  4. Decide it cannot be handled now, and to retry it later (no equivalent)
  5. Defer its passing down the chain to a later point (no equivalent)

Example

Sequence::of($import)
  ->peek(function($record) { Console::write($record['name']); })
  ->process(function($processing, $record) {
    $existing= $this->database->lookup($record['name']);
    try {
      return $this->database->replace($existing, $record);
    } catch (InvalidRecord $e) {
      $processing->drop();
    } catch (DatabaseError $e) {
      $processing->retry($record, function() { sleep(5); });
    }
  }))
  ->peek(function($id) { Console::writeLine(' -> #', $id); )
  ->each()
;

thekid added 2 commits May 1, 2016 13:10
A processing function can handle the processing of elements passed to it
in the following ways:

1. Do something with and pass it on down the chain, just like peek()
2. Do something with and return a result, just like map()
3. Decide not to pass it on, just like filter()
4. Decide it cannot be handled now, and to retry it later (no equivalent)
5. Defer its passing down the chain to a later point (no equivalent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants