github.com/richardwilkes/toolbox@v1.121.0/collection/slice/slice.go (about)

     1  // Copyright (c) 2016-2024 by Richard A. Wilkes. All rights reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the Mozilla Public
     4  // License, version 2.0. If a copy of the MPL was not distributed with
     5  // this file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6  //
     7  // This Source Code Form is "Incompatible With Secondary Licenses", as
     8  // defined by the Mozilla Public License, version 2.0.
     9  
    10  package slice
    11  
    12  import "slices"
    13  
    14  // ZeroedDelete removes the elements s[i:j] from s, returning the modified slice. This function panics if s[i:j] is not
    15  // a valid slice of s. This function modifies the contents of the slice s; it does not create a new slice. The elements
    16  // that are removed are zeroed so that any references can be garbage collected. If you do not need this, use
    17  // slices.Delete instead.
    18  //
    19  // Deprecated: As of Go 1.22, slices.Delete now zeroes out removed elements, so use it instead. This function was
    20  // deprecated on March 29, 2024 and will be removed on or after January 1, 2025.
    21  func ZeroedDelete[S ~[]E, E any](s S, i, j int) S {
    22  	return slices.Delete(s, i, j)
    23  }
    24  
    25  // ZeroedDeleteFunc removes any elements from s for which del returns true, returning the modified slice. This function
    26  // modifies the contents of the slice s; it does not create a new slice. The elements that are removed are zeroed so
    27  // that any references can be garbage collected. If you do not need this, use slices.DeleteFunc instead.
    28  //
    29  // Deprecated: As of Go 1.22, slices.DeleteFunc now zeroes out removed elements, so use it instead. This function was
    30  // deprecated on March 29, 2024 and will be removed on or after January 1, 2025.
    31  func ZeroedDeleteFunc[S ~[]E, E any](s S, del func(E) bool) S {
    32  	return slices.DeleteFunc(s, del)
    33  }