Skip to content

Commit b17318e

Browse files
committed
Improve docs of generic helpers
1 parent d463827 commit b17318e

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

neo4j/result_helpers.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ import (
2424
"fmt"
2525
)
2626

27-
// SingleTWithContext is like SingleT. It accepts a context.Context parameter
27+
// SingleTWithContext maps the single record left to an instance of T with the provided mapper function.
28+
// It relies on ResultWithContext.Single and propagate its error, if any.
29+
// It accepts a context.Context, which may be canceled or carry a deadline, to control the overall record fetching
30+
// execution time.
2831
func SingleTWithContext[T any](ctx context.Context, result ResultWithContext, mapper func(*Record) (T, error)) (T, error) {
2932
single, err := result.Single(ctx)
3033
if err != nil {
@@ -33,7 +36,9 @@ func SingleTWithContext[T any](ctx context.Context, result ResultWithContext, ma
3336
return mapper(single)
3437
}
3538

36-
// SingleT is like Single but maps the single Record with the provided mapper.
39+
// SingleT maps the single record left to an instance of T with the provided mapper function.
40+
// It relies on Result.Single and propagate its error, if any.
41+
//
3742
// Deprecated: use SingleTWithContext instead (the entry point of context-aware
3843
// APIs is NewDriverWithContext)
3944
func SingleT[T any](result Result, mapper func(*Record) (T, error)) (T, error) {
@@ -44,7 +49,10 @@ func SingleT[T any](result Result, mapper func(*Record) (T, error)) (T, error) {
4449
return mapper(single)
4550
}
4651

47-
// CollectTWithContext is like CollectT. It accepts a context.Context parameter
52+
// CollectTWithContext maps the records to a slice of T with the provided mapper function.
53+
// It relies on ResultWithContext.Collect and propagate its error, if any.
54+
// It accepts a context.Context, which may be canceled or carry a deadline, to control the overall record fetching
55+
// execution time.
4856
func CollectTWithContext[T any](ctx context.Context, result ResultWithContext, mapper func(*Record) (T, error)) ([]T, error) {
4957
records, err := result.Collect(ctx)
5058
if err != nil {
@@ -53,7 +61,9 @@ func CollectTWithContext[T any](ctx context.Context, result ResultWithContext, m
5361
return mapAll(records, mapper)
5462
}
5563

56-
// CollectT is like Collect but maps each record with the provided mapper.
64+
// CollectT maps the records to a slice of T with the provided mapper function.
65+
// It relies on Result.Collect and propagate its error, if any.
66+
//
5767
// Deprecated: use CollectTWithContext instead (the entry point of context-aware
5868
// APIs is NewDriverWithContext)
5969
func CollectT[T any](result Result, mapper func(*Record) (T, error)) ([]T, error) {
@@ -76,7 +86,8 @@ func Single(result Result, err error) (*Record, error) {
7686
return result.Single()
7787
}
7888

79-
// Collect behaves similarly to CollectWithContext
89+
// Collect aggregates the records into a slice.
90+
// It relies on Result.Collect and propagate its error, if any.
8091
//
8192
// records, err := neo4j.Collect(session.Run(...))
8293
//
@@ -89,14 +100,14 @@ func Collect(result Result, err error) ([]*Record, error) {
89100
return result.Collect()
90101
}
91102

92-
// CollectWithContext loops through the result stream, collects records into a slice and returns the
93-
// resulting slice. Any error passed in or reported while navigating the result stream is
94-
// returned without any conversion.
103+
// CollectWithContext aggregates the records into a slice.
104+
// It relies on ResultWithContext.Collect and propagate its error, if any.
95105
//
96106
// result, err := session.Run(...)
97107
// records, err := neo4j.CollectWithContext(ctx, result, err)
98108
//
99-
// Note, you cannot write neo4j.CollectWithContext(ctx, session.Run(...)) due to Go limitations
109+
// It accepts a context.Context, which may be canceled or carry a deadline, to control the overall record fetching
110+
// execution time.
100111
func CollectWithContext(ctx context.Context, result ResultWithContext, err error) ([]*Record, error) {
101112
if err != nil {
102113
return nil, err

0 commit comments

Comments
 (0)