Skip to content

Commit

Permalink
add doc to collect
Browse files Browse the repository at this point in the history
  • Loading branch information
emicklei committed Sep 10, 2024
1 parent 03c4bd9 commit 6fbcbf7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 5 additions & 3 deletions dsl/eval_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ onkey('c4',onoff('e')) // uses default input and default output MIDI device`,

registerFunction(eval, "euclidean", Function{
Title: "Music Pattern Generator: Euclidean",
Description: "",
Description: "euclidean creates a euclidean rythm generator",
Template: "euclidean(${1:steps},${2:beats},${3:rotation},${4:noteOrVariable})",
Samples: "",
Func: func(steps, beats, rotation, noteOrVariable any) any {
Expand All @@ -1291,9 +1291,11 @@ onkey('c4',onoff('e')) // uses default input and default output MIDI device`,

registerFunction(eval, "collect", Function{
Title: "Collect function",
Description: "",
Description: "collect will map each sequence of a collection using a function that references a replacement",
Template: "collect(${1:collection},${2:function-with-underscore})",
Samples: "",
Samples: `j = join(sequence('C E G'),sequence('D F A'))
// uses the special variable named "_"
c = collect(j, transpose(1, _ ))`,
Func: func(collection any, function any) any {
if _, ok := getValue(collection).(core.HasSequenceables); !ok {
return notify.Panic(errors.New("collection must have sequenceables"))
Expand Down
16 changes: 15 additions & 1 deletion dsl/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func TestEuclidean(t *testing.T) {
}
}

func TestCollect(t *testing.T) {
func TestCollecFraction(t *testing.T) {
e := newTestEvaluator()
r, err := e.EvaluateProgram(`
Expand All @@ -275,4 +275,18 @@ func TestCollect(t *testing.T) {
if got, want := r.(core.Collect).Storex(), "collect(join(note('E')),fraction(8,_))"; got != want {
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
}
if got, want := r.(core.Collect).S().Storex(), "sequence('8E')"; got != want {
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
}
}
func TestCollecTranspose(t *testing.T) {
e := newTestEvaluator()
r, err := e.EvaluateProgram(`
c = collect(join(note('e')), transpose(1,_))
`)
checkError(t, err)
if got, want := r.(core.Collect).S().Storex(), "sequence('F')"; got != want {
t.Errorf("got [%v:%T] want [%v:%T]", got, got, want, want)
}
}

0 comments on commit 6fbcbf7

Please sign in to comment.