MCPcopy
hub / github.com/gogf/gf / ExampleIntSet_AddIfNotExist

Function ExampleIntSet_AddIfNotExist

container/gset/gset_z_example_int_test.go:53–62  ·  view source on GitHub ↗

AddIfNotExist checks whether item exists in the set, it adds the item to set and returns true if it does not exists in the set, or else it does nothing and returns false.

()

Source from the content-addressed store, hash-verified

51// it adds the item to set and returns true if it does not exists in the set,
52// or else it does nothing and returns false.
53func ExampleIntSet_AddIfNotExist() {
54 intSet := gset.NewIntSetFrom([]int{1, 2, 3})
55 intSet.Add(1)
56 fmt.Println(intSet.Slice())
57 fmt.Println(intSet.AddIfNotExist(1))
58
59 // May Output:
60 // [1 2 3]
61 // false
62}
63
64// AddIfNotExistFunc checks whether item exists in the set,
65// it adds the item to set and returns true if it does not exists in the set and function `f` returns true,

Callers

nothing calls this directly

Calls 4

NewIntSetFromFunction · 0.92
AddMethod · 0.65
SliceMethod · 0.45
AddIfNotExistMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…