<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Sorting on Nalar</title>
    <link>https://nalar.dev/tags/sorting/</link>
    <description>Recent content in Sorting on Nalar</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Fri, 11 Sep 2026 00:00:00 +0700</lastBuildDate>
    <atom:link href="https://nalar.dev/tags/sorting/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Check Custom Slice Ordering in Go with slices.IsSortedFunc</title>
      <link>https://nalar.dev/check-custom-slice-ordering-with-slices-issortedfunc/</link>
      <pubDate>Fri, 11 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/check-custom-slice-ordering-with-slices-issortedfunc/</guid>
      <description>&lt;p&gt;Sometimes you need to know whether a slice is already in the right order, not sort it again. That comes up when validating API input, checking an invariant before binary search, or avoiding unnecessary work when records are expected to arrive ordered.&lt;/p&gt;&#xA;&lt;p&gt;For plain numbers and strings, &lt;code&gt;slices.IsSorted&lt;/code&gt; handles the common case. When the elements are structs or the ordering is application-specific, &lt;code&gt;slices.IsSortedFunc&lt;/code&gt; lets you define exactly what “sorted” means and returns a boolean without rearranging the slice.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Preserve Equal Element Order in Go with slices.SortStableFunc</title>
      <link>https://nalar.dev/preserve-equal-element-order-with-slices-sortstablefunc/</link>
      <pubDate>Fri, 11 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/preserve-equal-element-order-with-slices-sortstablefunc/</guid>
      <description>&lt;p&gt;Sometimes sorting by one field is only half the requirement. You may want jobs grouped by priority while keeping their arrival order inside each priority, or records grouped by category without disturbing an earlier ranking.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;slices.SortStableFunc&lt;/code&gt; is built for that case. It sorts a slice in place using a custom comparator, but elements that compare equal keep their original relative order.&lt;/p&gt;&#xA;&lt;h2 id=&#34;preserve-equal-elements-with-slicessortstablefunc&#34;&gt;Preserve equal elements with slices.SortStableFunc&lt;/h2&gt;&#xA;&lt;p&gt;Suppose jobs arrive in this order:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Sort Struct Slices in Go with slices.SortFunc</title>
      <link>https://nalar.dev/sort-struct-slices-in-go-with-slices-sortfunc/</link>
      <pubDate>Fri, 11 Sep 2026 00:00:00 +0700</pubDate>
      <guid>https://nalar.dev/sort-struct-slices-in-go-with-slices-sortfunc/</guid>
      <description>&lt;p&gt;Sorting a slice of structs usually starts with a simple requirement such as “priority first, then ID.” The awkward part is expressing that ordering clearly enough that sorting, validation, and binary search can all agree on it.&lt;/p&gt;&#xA;&lt;p&gt;&lt;code&gt;slices.SortFunc&lt;/code&gt; handles this directly. You give it the slice and a comparator that defines the order. It sorts the existing slice in place, so there is no separate result to assign.&lt;/p&gt;&#xA;&lt;h2 id=&#34;sort-a-struct-slice-with-slicessortfunc&#34;&gt;Sort a struct slice with slices.SortFunc&lt;/h2&gt;&#xA;&lt;p&gt;Suppose a queue contains jobs that should be ordered by ascending priority and then by ID when priorities match:&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
