<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Equatable Protocol on Daniel Lyons</title><link>https://dandylyons.net/topics/equatable-protocol/</link><description>Recent content in Equatable Protocol on Daniel Lyons</description><generator>Hugo -- gohugo.io</generator><language>en-gb</language><lastBuildDate>Thu, 12 Dec 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://dandylyons.net/topics/equatable-protocol/index.xml" rel="self" type="application/rss+xml"/><item><title>Introducing SelectiveEquatable</title><link>https://dandylyons.net/posts/selectiveequatable/</link><pubDate>Thu, 12 Dec 2024 00:00:00 +0000</pubDate><guid>https://dandylyons.net/posts/selectiveequatable/</guid><description>&lt;p>A few weeks ago, I released a blog post named &lt;a href="https://dandylyons.net/posts/post-24/selective-equality-checking-in-swift/">&amp;ldquo;Selective Equality Checking in Swift&amp;rdquo;&lt;/a>. In that post, I designed and implemented an API to check for equality on specific properties of a type. Today, I am excited to announce a new Swift protocol named &lt;code>SelectiveEquatable&lt;/code>, that makes all of this even easier. Let&amp;rsquo;s see it in action.&lt;/p>
&lt;h2 id="using-selectiveequatable">Using SelectiveEquatable&lt;/h2>
&lt;p>To use the &lt;code>SelectiveEquatable&lt;/code> protocol, all you need to do is add a conformance to it like this:&lt;/p></description></item><item><title>Selective Equality Checking in Swift</title><link>https://dandylyons.net/posts/selective-equality-checking-in-swift/</link><pubDate>Tue, 05 Nov 2024 00:00:00 +0000</pubDate><guid>https://dandylyons.net/posts/selective-equality-checking-in-swift/</guid><description>&lt;p>The humble &lt;code>Equatable&lt;/code> protocols is one of the most fundamental tools in Swift, but sometimes it is not always the best tool for the job. Last week we learned how to &lt;a href="https://dandylyons.net/posts/unordered-equality-checking-in-swift/">check equality for collections while ignoring order&lt;/a>. Today we will learn how to pick and choose exactly what properties we would like to check equality on. But first let&amp;rsquo;s talk about the problem:&lt;/p>
&lt;h2 id="why-not-just-use-equatable">Why Not Just Use Equatable&lt;/h2>
&lt;p>For the majority of use cases the best option is to just use the plain old &lt;code>==&lt;/code> operator. We get this operator automatically when a type conforms to &lt;code>Equatable&lt;/code>. However it&amp;rsquo;s not always easy conform to &lt;code>Equatable&lt;/code>. Here are some situations when it might not be feasible or even possible to conform to &lt;code>Equatable&lt;/code>.&lt;/p></description></item><item><title>Unordered Equality Checking in Swift</title><link>https://dandylyons.net/posts/unordered-equality-checking-in-swift/</link><pubDate>Tue, 29 Oct 2024 00:00:00 +0000</pubDate><guid>https://dandylyons.net/posts/unordered-equality-checking-in-swift/</guid><description>&lt;p>Have you ever needed to compare two arrays in Swift, but the order of elements doesn&amp;rsquo;t matter? I find this often happens to me when convert between an ordered type such as &lt;code>Array&lt;/code> and an unordered type such as &lt;code>Set&lt;/code> or &lt;code>Dictionary&lt;/code>. Today, we&amp;rsquo;ll explore how to implement &lt;strong>unordered equality checking&lt;/strong> in Swift, starting with the basics and working our way up to a flexible, protocol-based solution.&lt;/p>
&lt;h2 id="what-is-deep-equality">What is Deep Equality?&lt;/h2>
&lt;p>Before diving into unordered equality, let&amp;rsquo;s briefly discuss deep equality. Many programming languages struggle with deep equality comparisons. Take JavaScript, for example:&lt;/p></description></item></channel></rss>