Skip to content

Commit 1f71a76

Browse files
committed
better docs for T functions
1 parent 66f2de5 commit 1f71a76

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

try/try.go

+16
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ func IsNotEnabled(err error) bool {
261261
// T is similar as [To] but it let's you to annotate a possible error at place.
262262
//
263263
// try.T(f.Close)("annotations")
264+
//
265+
// Note that T is a helper, which means that you start with it randomly. You
266+
// start with [To] and end up using T if you really need to add context
267+
// related to a specific error check, which is a very rare case.
264268
func T(err error) func(fs string) {
265269
return func(fs string) {
266270
if err == nil {
@@ -273,6 +277,10 @@ func T(err error) func(fs string) {
273277
// T1 is similar as [To1] but it let's you to annotate a possible error at place.
274278
//
275279
// f := try.T1(os.Open("filename")("cannot open cfg file")
280+
//
281+
// Note that T1 is a helper, which means that you start with it randomly. You
282+
// start with [To1] and end up using T1 if you really need to add context
283+
// related to a specific error check, which is a very rare case.
276284
func T1[T any](v T, err error) func(fs string) T {
277285
return func(fs string) T {
278286
if err == nil {
@@ -283,6 +291,10 @@ func T1[T any](v T, err error) func(fs string) T {
283291
}
284292

285293
// T2 is similar as [To2] but it let's you to annotate a possible error at place.
294+
//
295+
// Note that T2 is a helper, which means that you start with it randomly. You
296+
// start with [To2] and end up using T2 if you really need to add context
297+
// related to a specific error check, which is a very rare case.
286298
func T2[T, U any](v T, u U, err error) func(fs string) (T, U) {
287299
return func(fs string) (T, U) {
288300
if err == nil {
@@ -298,6 +310,10 @@ func annotateErr(err error, fs string) error {
298310
}
299311

300312
// T3 is similar as [To3] but it let's you to annotate a possible error at place.
313+
//
314+
// Note that T3 is a helper, which means that you start with it randomly. You
315+
// start with [To3] and end up using T3 if you really need to add context
316+
// related to a specific error check, which is a very rare case.
301317
func T3[T, U, V any](v1 T, v2 U, v3 V, err error) func(fs string) (T, U, V) {
302318
return func(fs string) (T, U, V) {
303319
if err == nil {

0 commit comments

Comments
 (0)