Skip to content

Commit

Permalink
Add examples for using tuples in maps and channels to README (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
barweiss authored Mar 24, 2022
1 parent 56a6488 commit be1a4ae
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,25 @@ Tuples come in various sizes, from 1 to 9 elements.
longerTuple := tuple.New5("this", "is", "one", "long", "tuple")
```

Tuples can be used as slice or array items, map keys or values, and as channel payloads.
Tuples can be used as slice or array items, map keys or values, and as channel payloads:

```go
// Map holding tuples.
tupInMap := make(map[tuple.T2[string, string]]Person)
tupInMap[tuple.New2("John", "Doe")] = Person{
FirstName: "John",
LastName: "Doe",
// ...
}

// Channel holding tuples.
tupInChan := make(chan tuple.T2[string, error])
go func() {
defer close(tupInChan)
tupInChan <- tuple.New2(os.Getwd())
}()
fmt.Print(<-tupInChan)
```

# Features

Expand Down

0 comments on commit be1a4ae

Please sign in to comment.