PcollectFinal:
Filter:
ddwPatterns/Classes (extension) | Streams-Patterns-Events > Patterns > Filter

PcollectFinal
ExtensionExtension

Apply a function to each output value, and a separate function to the last value.

Description

Very much like Pcollect, with one difference:

This is useful for embedding phrase patterns in a longer stream, where you want the final note of the phrase to be shorter.

Caveats

PcollectFinal must look ahead in the stream by one value. It starts by getting two values and yielding the first. On the second call, it gets the third value and yields the second, and so on. This is the only way to know if the next value will be nil.

Potential problems:

WARNING: These caveats suggest that this may not be an ideal solution. If I find a better approach later, I may remove this class. Avoid relying on it too much.

Class Methods

.new

Arguments:

func

The function that will be applied to the first n - 1 items.

pattern

The source pattern.

finalFunc

The function that will be applied to the final item.

Examples