Debian Codegraph @

dstream/generate.go

raw symbols SCIP
1 package dstream
2
3 // GenerateFunc is a function that can be used to generate a new variable
4 // from existing variables. The first argument is a map from
5 // variable names to data (whose concrete types are slices held as
6 // empty interfaces). The second argument is a pre-allocated array (a
7 // slice provided as an interface{}) into which the new variable's
8 // values are to be written. Note that the destination array is not set to
9 // zeros before passing to the generate function.
10 type GenerateFunc func(map[string]interface{}, interface{})
11
12 type generate struct {
13 xform
14
15 gfunc GenerateFunc
16 newvarname string
17 dtype Dtype
18 }
19
20 // Generate appends a new variable to a Dstream, obtaining its values by
21 // applying the given function to the other variables in the Dstream.
22 // The new variable must not already exist in the Dstream.
23 func Generate(data Dstream, name string, fnc GenerateFunc, dtype Dtype) Dstream {
24
25 g := &generate{
26 xform: xform{
27 source: data,
28 },
29 newvarname: name,
30 gfunc: fnc,
31 dtype: dtype,
32 }
33 g.init()
34
35 return g
36 }