github.com/wangyougui/gf/v2@v2.6.5/util/gutil/gutil_z_example_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 this file,
     5  // You can obtain one at https://github.com/wangyougui/gf.
     6  
     7  package gutil_test
     8  
     9  import (
    10  	"fmt"
    11  	"github.com/wangyougui/gf/v2/frame/g"
    12  	"github.com/wangyougui/gf/v2/util/gutil"
    13  )
    14  
    15  func ExampleSliceInsertBefore() {
    16  	s1 := g.Slice{
    17  		0, 1, 2, 3, 4,
    18  	}
    19  	s2 := gutil.SliceInsertBefore(s1, 1, 8, 9)
    20  	fmt.Println(s1)
    21  	fmt.Println(s2)
    22  
    23  	// Output:
    24  	// [0 1 2 3 4]
    25  	// [0 8 9 1 2 3 4]
    26  }
    27  
    28  func ExampleSliceInsertAfter() {
    29  	s1 := g.Slice{
    30  		0, 1, 2, 3, 4,
    31  	}
    32  	s2 := gutil.SliceInsertAfter(s1, 1, 8, 9)
    33  	fmt.Println(s1)
    34  	fmt.Println(s2)
    35  
    36  	// Output:
    37  	// [0 1 2 3 4]
    38  	// [0 1 8 9 2 3 4]
    39  }