Pcollect.schelp 1011 Bytes
Newer Older
1 2 3 4 5 6
class:: Pcollect
summary:: Apply a function to a pattern
categories:: Streams-Patterns-Events>Patterns>Filter
related:: Classes/Pselect, Classes/Preject

description::
7
Modifies each value by passing it to the function. This is the pattern library's equivalent of link::Classes/Collection#-collect::.
8 9 10 11 12 13 14 15 16 17 18 19 20

classmethods::

method:: new
argument:: func
A link::Classes/Function::. Receives values from code::pattern::.
argument:: pattern
A link::Classes/Pattern::.


examples::
code::
(
21
a = Pcollect( { |item| item * 3 }, Pseq( #[ 1, 2, 3 ], inf ) );
22
x = a.asStream;
23
9.do( { x.next.postln; } );
24 25 26 27 28 29
)
::

The message code::collect:: returns a Pcollect when passed to a pattern. Note that because the pattern is converted to a link::Classes/Stream:: (more precisely a link::Classes/FuncStream::) the collect function is evaluated for one item each time the message code::next:: is passed.
code::
(
30
a = Pseq( #[ 1, 2, 3 ], inf ).collect( { arg item; item * 3 } );
31
a.postln;
32

33
x = a.asStream;
34
9.do( { x.next.postln; } );
35 36
)
::