1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-12 16:52:29 +08:00

maputil: IsDisjoint (#43)

Verifies map a and map b have no keys in common.

if it returns true then the maps are disjoint otherwise a join in some form available
This commit is contained in:
donutloop
2022-07-20 11:26:54 +02:00
committed by GitHub
parent ecf325a06c
commit 336e454ce7
4 changed files with 83 additions and 0 deletions

View File

@@ -301,4 +301,54 @@ func main() {
fmt.Println(values) // []string{"a", "a", "b", "c", "d"}
}
```
### <span id="Values">Values</span>
<p>Returns a boolean</p>
<b>Signature:</b>
```go
IsDisjoint[K comparable, V any](mapA, mapB map[K]V) bool
```
<b>Example:</b>
```go
package main
import (
"fmt"
"github.com/duke-git/lancet/v2/maputil"
)
func main() {
m1 := map[int]string{
1: "a",
2: "a",
3: "b",
4: "c",
5: "d",
}
m2 := map[int]string{
1: "a",
2: "a",
3: "b",
4: "c",
5: "d",
}
m3 := map[int]string{
6: "a",
}
ok := maputil.IsDisjoint(m2, m1)
fmt.Println(ok) // false
ok = maputil.IsDisjoint(m2, m3)
fmt.Println(ok) // true
}
```