Skip to content

Commit 3cbad44

Browse files
committed
Added more documentation for queries that take callbacks
1 parent 5d42a7d commit 3cbad44

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

query_aggregation.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ import (
77
// Aggregation
88
// These commands are used to compute smaller values from large sequences.
99

10-
// Produce a single value from a sequence through repeated application of a
11-
// reduction function
10+
// Reduce produces a single value from a sequence through repeated application
11+
// of a reduction function
12+
//
13+
// It takes one argument of type `func (r.Term, r.Term) interface{}`, for
14+
// example this query sums all elements in an array:
15+
//
16+
// r.Expr([]int{1,3,6}).Reduce(func (left, right r.Term) interface{} {
17+
// return left.Add(right)
18+
// })
1219
func (t Term) Reduce(args ...interface{}) Term {
1320
return constructMethodTerm(t, "Reduce", p.Term_REDUCE, funcWrapArgs(args), map[string]interface{}{})
1421
}

query_control.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,14 @@ func Branch(args ...interface{}) Term {
220220
return constructRootTerm("Branch", p.Term_BRANCH, args, map[string]interface{}{})
221221
}
222222

223-
// Loop over a sequence, evaluating the given write query for each element.
223+
// ForEach loops over a sequence, evaluating the given write query for each element.
224+
//
225+
// It takes one argument of type `func (r.Term) interface{}`, for
226+
// example clones a table:
227+
//
228+
// r.Table("table").ForEach(func (row r.Term) interface{} {
229+
// return r.Table("new_table").Insert(row)
230+
// })
224231
func (t Term) ForEach(args ...interface{}) Term {
225232
return constructMethodTerm(t, "Foreach", p.Term_FOR_EACH, funcWrapArgs(args), map[string]interface{}{})
226233
}

query_transformation.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ package gorethink
22

33
import p "github.com/dancannon/gorethink/ql2"
44

5-
// Transform each element of the sequence by applying the given mapping function.
5+
// Map transform each element of the sequence by applying the given mapping
6+
// function. It takes two arguments, a sequence and a function of type
7+
// `func (r.Term) interface{}`.
8+
//
9+
// For example this query doubles each element in an array:
10+
//
11+
// r.Map([]int{1,3,6}, func (row r.Term) interface{} {
12+
// return row.Mul(2)
13+
// })
614
func Map(args ...interface{}) Term {
715
if len(args) > 0 {
816
args = append(args[:len(args)-1], funcWrapArgs(args[len(args)-1:])...)
@@ -11,7 +19,14 @@ func Map(args ...interface{}) Term {
1119
return constructRootTerm("Map", p.Term_MAP, funcWrapArgs(args), map[string]interface{}{})
1220
}
1321

14-
// Transfor >m each element of the sequence by applying the given mapping function.
22+
// Map transforms each element of the sequence by applying the given mapping
23+
// function. It takes one argument of type `func (r.Term) interface{}`.
24+
//
25+
// For example this query doubles each element in an array:
26+
//
27+
// r.Expr([]int{1,3,6}).Map(func (row r.Term) interface{} {
28+
// return row.Mul(2)
29+
// })
1530
func (t Term) Map(args ...interface{}) Term {
1631
return constructMethodTerm(t, "Map", p.Term_MAP, funcWrapArgs(args), map[string]interface{}{})
1732
}

0 commit comments

Comments
 (0)