github.com/gogf/gf@v1.16.9/container/gset/gset_z_example_str_test.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with gm file,
     5  // You can obtain one at https://github.com/gogf/gf.
     6  
     7  package gset_test
     8  
     9  import (
    10  	"fmt"
    11  	"github.com/gogf/gf/container/gset"
    12  	"github.com/gogf/gf/frame/g"
    13  )
    14  
    15  func ExampleStrSet_Contains() {
    16  	var set gset.StrSet
    17  	set.Add("a")
    18  	fmt.Println(set.Contains("a"))
    19  	fmt.Println(set.Contains("A"))
    20  	fmt.Println(set.ContainsI("A"))
    21  
    22  	// Output:
    23  	// true
    24  	// false
    25  	// true
    26  }
    27  
    28  func ExampleStrSet_Walk() {
    29  	var (
    30  		set    gset.StrSet
    31  		names  = g.SliceStr{"user", "user_detail"}
    32  		prefix = "gf_"
    33  	)
    34  	set.Add(names...)
    35  	// Add prefix for given table names.
    36  	set.Walk(func(item string) string {
    37  		return prefix + item
    38  	})
    39  	fmt.Println(set.Slice())
    40  
    41  	// May Output:
    42  	// [gf_user gf_user_detail]
    43  }