@@ -21,11 +21,35 @@ object Test {
21
21
}
22
22
}
23
23
24
+ /** * Producer represents a linear production of values.
25
+ *
26
+ * Conceptually the design of the producer has its roots in `unfold` where a stream is a product type of some state
27
+ * and a stepper function. The latter transforms the state and returns either the end-of-the-stream or a value and
28
+ * the new state. The existential quantification over the state keeps it private: the only permissible operation is
29
+ * to pass it to the step function.
30
+ *
31
+ * @tparam A type of the collection elements
32
+ */
24
33
trait Producer [A ] { self =>
25
34
type St
26
35
val card : Cardinality
27
36
37
+ /** Initialization method that defines new state, if needed by the combinator that this producer defines.
38
+ *
39
+ * e.g., `addCounter` which adds a counter
40
+ *
41
+ * @param k the continuation that is invoked after the new state is defined in the body of `init`
42
+ * @return expr value of unit per the CPS-encoding
43
+ */
28
44
def init (k : St => Expr [Unit ]): Expr [Unit ]
45
+
46
+ /** Step method that defines the transformation of data, if applicable.
47
+ *
48
+ *
49
+ * @param st
50
+ * @param k
51
+ * @return
52
+ */
29
53
def step (st : St , k : (A => Expr [Unit ])): Expr [Unit ]
30
54
def hasNext (st : St ): Expr [Boolean ]
31
55
}
@@ -183,7 +207,7 @@ object Test {
183
207
Stream (flatMapRaw[Expr [A ], Expr [A ]]((a => { Linear (filterStream(a)) }), stream))
184
208
}
185
209
186
- /** Adds a new termination condition to a producer of cardinality `Many`.
210
+ /** Adds a new termination condition to a stream (recursively if nested) of cardinality `Many`.
187
211
*
188
212
* @param condition the termination condition as a function accepting the existing condition (the result
189
213
* of the `hasNext` from the passed `stream`'s producer.
0 commit comments