# Slices Package: Clip, Clone, and Compact

DevFeed: [Slices Package: Clip, Clone, and Compact](<https://devfeed.tech/articles/slices-package-clip-clone-and-compact-22225.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2023/08/golang-slices-clip-clone-compact.html>)

Published: 2023-08-18T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [Library](<https://devfeed.tech/topics/library.md>), [Code](<https://devfeed.tech/topics/code.md>), [SDKs](<https://devfeed.tech/topics/sdks.md>)

Tags: [apis](<https://devfeed.tech/tags/apis.md>), [code](<https://devfeed.tech/tags/code.md>), [go](<https://devfeed.tech/tags/go.md>), [golang](<https://devfeed.tech/tags/golang.md>), [library](<https://devfeed.tech/tags/library.md>), [slices](<https://devfeed.tech/tags/slices.md>), [standard-library](<https://devfeed.tech/tags/standard-library.md>)

## AI overview

This tutorial explains how the Go slices package APIs Clip, Clone, and Compact work. It shows how Clip reduces a slice's capacity to its length and describes Clone as a shallow copy of the backing-array elements.

## Source excerpt

Series Here are all the posts in this series about the slices package. Binary Search Clip, Clone, and Compact Compare Contains, Delete, and Equal Introduction In the first post of this series, I discussed the binary search API from the slices package that is now part of the standard library with the release of version 1.21. In this post, I will share how the Clip, Clone, and Compact APIs work. Clip The Clip API can be used to remove unused capacity from a slice. This means reducing the capacity of the slice to match its length.