# Slices Package: Compare

DevFeed: [Slices Package: Compare](<https://devfeed.tech/articles/slices-package-compare-22226.md>)

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

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

Content type: tutorial

Language: en

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

Topics: [Go Language](<https://devfeed.tech/topics/go-language.md>), [API](<https://devfeed.tech/topics/api.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [code](<https://devfeed.tech/tags/code.md>), [examples](<https://devfeed.tech/tags/examples.md>), [function](<https://devfeed.tech/tags/function.md>), [generics](<https://devfeed.tech/tags/generics.md>), [go](<https://devfeed.tech/tags/go.md>), [golang](<https://devfeed.tech/tags/golang.md>)

## AI overview

This tutorial explains how Go's slices package Compare and CompareFunc APIs compare slices for equality or ordering. It demonstrates comparisons of integer slices and slices of structs using a custom comparison function and generics.

## 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 last post of this series I discussed the Clip, Clone, and Compact APIs from the slices package. In this post, I will share how the Compare and CompareFunc APIs work. Compare The Compare API can be used to compare two slices and determine if the slices are equal or which one is shorter. Shorter meaning the slice with the lesser of the two values at the same index position. Less can be obvious like with integers, or needs to be custom defined like with structs.