Skip to content

Commit be1a4ae

Browse files
authored
Add examples for using tuples in maps and channels to README (#17)
1 parent 56a6488 commit be1a4ae

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,25 @@ Tuples come in various sizes, from 1 to 9 elements.
2121
longerTuple := tuple.New5("this", "is", "one", "long", "tuple")
2222
```
2323

24-
Tuples can be used as slice or array items, map keys or values, and as channel payloads.
24+
Tuples can be used as slice or array items, map keys or values, and as channel payloads:
25+
26+
```go
27+
// Map holding tuples.
28+
tupInMap := make(map[tuple.T2[string, string]]Person)
29+
tupInMap[tuple.New2("John", "Doe")] = Person{
30+
FirstName: "John",
31+
LastName: "Doe",
32+
// ...
33+
}
34+
35+
// Channel holding tuples.
36+
tupInChan := make(chan tuple.T2[string, error])
37+
go func() {
38+
defer close(tupInChan)
39+
tupInChan <- tuple.New2(os.Getwd())
40+
}()
41+
fmt.Print(<-tupInChan)
42+
```
2543

2644
# Features
2745

0 commit comments

Comments
 (0)