<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Slice on Gopher Coding</title><link>https://gophercoding.com/tags/slice/</link><description>Recent content in Slice on Gopher Coding</description><generator>Hugo</generator><language>en-gb</language><lastBuildDate>Wed, 17 Jan 2024 20:33:54 +0000</lastBuildDate><atom:link href="https://gophercoding.com/tags/slice/index.xml" rel="self" type="application/rss+xml"/><item><title>Find the Min or Max Value in a Slice (New to Go 1.21)</title><link>https://gophercoding.com/using-min-max-on-slice/</link><pubDate>Sun, 23 Jul 2023 07:00:00 +0000</pubDate><guid>https://gophercoding.com/using-min-max-on-slice/</guid><description>&lt;p>The latest Go release, 1.21, has introduced two new built-in functions: &lt;code>min()&lt;/code> and &lt;code>max()&lt;/code>. These functions have long been used in many other languages, such as Python and JavaScript, and are now welcome additions to Go.&lt;/p>
&lt;p>The min() and max() functions have been introduced to simplify the process of finding the smallest and largest numbers in a set, respectively. There was &lt;a href="https://github.com/golang/go/issues/59488#issuecomment-1548505279">plenty of talk&lt;/a> as to whether these should be included as &amp;ldquo;built-ins&amp;rdquo; or introduced into the cmp package.&lt;/p></description></item><item><title>How to Write Data to CSV in Go</title><link>https://gophercoding.com/saving-data-to-csv/</link><pubDate>Sat, 11 Feb 2023 13:00:00 +0000</pubDate><guid>https://gophercoding.com/saving-data-to-csv/</guid><description>&lt;p>In Go, you can use the standard library package &lt;code>encoding/csv&lt;/code> [&lt;a href="https://pkg.go.dev/encoding/csv">docs&lt;/a>] to write data to a CSV file. Below is a example that shows you how you can write a slice of user-data related strings to a CSV file.&lt;/p>
&lt;p>The code creates a new file called &lt;code>users.csv&lt;/code> and writes a slice of records to it. Finally, the Flush method is used to flush any buffered data to the underlying io.Writer, which is the file.&lt;/p></description></item><item><title>Find the Length of an Array</title><link>https://gophercoding.com/find-length-of-array/</link><pubDate>Thu, 15 Sep 2022 15:00:00 +0000</pubDate><guid>https://gophercoding.com/find-length-of-array/</guid><description>&lt;p>You can find the length of an &lt;strong>array&lt;/strong>, or to be correct a &lt;em>slice&lt;/em> or &lt;em>map&lt;/em>, in Go by using the standard library function &lt;code>len()&lt;/code>. We use the term array loosely here, as a general variable holding multiple things. Maps tend to have defined keys, whereas slices don&amp;rsquo;t (&lt;a href="https://boltandnuts.wordpress.com/2017/11/20/go-slice-vs-maps/">more info on the difference here&lt;/a>).&lt;/p>
&lt;p>We have shown both as examples below, how to get the length of a slice and how to get the length of a map. In Golang, the method is the same for both.&lt;/p></description></item></channel></rss>