<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Slices on Nalar</title>
    <link>https://nalar.dev/tags/slices/</link>
    <description>Recent content in Slices on Nalar</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Thu, 10 Sep 2026 00:00:00 +0700</lastBuildDate>
    <atom:link href="https://nalar.dev/tags/slices/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Append Iterator Values to Go Slices with slices.AppendSeq</title>
      <link>https://nalar.dev/append-iterator-values-to-slices-with-slices-appendseq/</link>
      <pubDate>Thu, 10 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/append-iterator-values-to-slices-with-slices-appendseq/</guid>
      <description>&lt;p&gt;An iterator is convenient while data is flowing through a pipeline, but sooner or later you may need those values in a slice. If you already have a destination slice, collecting the iterator separately and then appending it creates an unnecessary intermediate step.&lt;/p&gt;&#xA;&lt;p&gt;Go 1.23 added &lt;code&gt;slices.AppendSeq&lt;/code&gt; for exactly this boundary. It consumes an &lt;code&gt;iter.Seq&lt;/code&gt;, appends each yielded value to an existing slice, and returns the resulting slice.&lt;/p&gt;&#xA;&lt;h2 id=&#34;what-slicesappendseq-does&#34;&gt;What slices.AppendSeq does&lt;/h2&gt;&#xA;&lt;p&gt;The function has a compact signature:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Process Go Slices in Batches with slices.Chunk</title>
      <link>https://nalar.dev/process-slices-in-batches-with-slices-chunk/</link>
      <pubDate>Thu, 10 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/process-slices-in-batches-with-slices-chunk/</guid>
      <description>&lt;p&gt;Batching a slice sounds simple until the loop starts collecting edge cases: the final batch may be short, an empty input needs sensible behavior, and careless subslicing can leave each batch with capacity to overwrite later elements.&lt;/p&gt;&#xA;&lt;p&gt;Go 1.23 added &lt;code&gt;slices.Chunk&lt;/code&gt;, which handles that bookkeeping and exposes the batches as an iterator. If you already have the data in a slice and want to process consecutive groups without first building a &lt;code&gt;[][]T&lt;/code&gt;, it&amp;rsquo;s a useful small tool.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Remove Consecutive Duplicates in Go with slices.Compact</title>
      <link>https://nalar.dev/remove-consecutive-duplicates-in-go-with-slices-compact/</link>
      <pubDate>Thu, 10 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/remove-consecutive-duplicates-in-go-with-slices-compact/</guid>
      <description>&lt;p&gt;If a Go slice contains repeated values next to each other, you don&amp;rsquo;t need to write an index-heavy loop to collapse them. Since Go 1.21, &lt;code&gt;slices.Compact&lt;/code&gt; handles that operation directly for comparable element types.&lt;/p&gt;&#xA;&lt;p&gt;The word &lt;em&gt;consecutive&lt;/em&gt; matters. Given &lt;code&gt;[]string{&amp;quot;api&amp;quot;, &amp;quot;api&amp;quot;, &amp;quot;web&amp;quot;, &amp;quot;api&amp;quot;}&lt;/code&gt;, the result is &lt;code&gt;[]string{&amp;quot;api&amp;quot;, &amp;quot;web&amp;quot;, &amp;quot;api&amp;quot;}&lt;/code&gt;. The last &lt;code&gt;&amp;quot;api&amp;quot;&lt;/code&gt; stays because it belongs to a different run. &lt;code&gt;slices.Compact&lt;/code&gt; isn&amp;rsquo;t a general-purpose &amp;ldquo;unique values&amp;rdquo; function.&lt;/p&gt;&#xA;&lt;h2 id=&#34;what-slicescompact-actually-does&#34;&gt;What slices.Compact actually does&lt;/h2&gt;&#xA;&lt;p&gt;&lt;code&gt;slices.Compact&lt;/code&gt; replaces each consecutive run of equal elements with its first element. It modifies the slice&amp;rsquo;s backing array and returns a slice with the resulting length.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
