Skip to content

Commit d717448

Browse files
authored
Merge pull request #39 from ra1028/optional-ContentEquatable
Make Optional conform to ContentEquatable
2 parents 403a3ab + 5eac3a8 commit d717448

21 files changed

Lines changed: 313 additions & 19 deletions

DifferenceKit.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = 'DifferenceKit'
3-
spec.version = '0.7.0'
3+
spec.version = '0.7.1'
44
spec.author = { 'ra1028' => 'r.fe51028.r@gmail.com' }
55
spec.homepage = 'https://github.com/ra1028/DifferenceKit'
66
spec.documentation_url = 'https://ra1028.github.io/DifferenceKit'

DifferenceKit.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
6B2DF878210E2C12004D2D40 /* DifferenceKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6B2DF86E210E2C12004D2D40 /* DifferenceKit.framework */; };
1111
6B444B392163312700AEE32B /* ContentEquatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B444B382163312700AEE32B /* ContentEquatable.swift */; };
12+
6B444B3F2165E3D700AEE32B /* ContentEquatableTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B444B3E2165E3D700AEE32B /* ContentEquatableTest.swift */; };
1213
6B5B409C211066BF00A931DB /* AlgorithmTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B5B4093211066BF00A931DB /* AlgorithmTest.swift */; };
1314
6B5B409D211066BF00A931DB /* ArraySectionTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B5B4094211066BF00A931DB /* ArraySectionTest.swift */; };
1415
6B5B409E211066BF00A931DB /* StagedChangesetTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B5B4095211066BF00A931DB /* StagedChangesetTest.swift */; };
@@ -44,6 +45,7 @@
4445
6B2DF877210E2C12004D2D40 /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
4546
6B2DF88A210E39A8004D2D40 /* DifferenceKit.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = DifferenceKit.xcconfig; sourceTree = "<group>"; };
4647
6B444B382163312700AEE32B /* ContentEquatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentEquatable.swift; sourceTree = "<group>"; };
48+
6B444B3E2165E3D700AEE32B /* ContentEquatableTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentEquatableTest.swift; sourceTree = "<group>"; };
4749
6B5B4086211066B300A931DB /* Algorithm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Algorithm.swift; sourceTree = "<group>"; };
4850
6B5B4088211066B300A931DB /* UIKitExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIKitExtension.swift; sourceTree = "<group>"; };
4951
6B5B408A211066B300A931DB /* ArraySection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArraySection.swift; sourceTree = "<group>"; };
@@ -148,6 +150,7 @@
148150
6B5B4096211066BF00A931DB /* AnyDifferentiableTest.swift */,
149151
6B5B4097211066BF00A931DB /* ElementPathTest.swift */,
150152
6B5B4098211066BF00A931DB /* ChangesetTest.swift */,
153+
6B444B3E2165E3D700AEE32B /* ContentEquatableTest.swift */,
151154
6B5B4099211066BF00A931DB /* MeasurementTest.swift */,
152155
6B5B409B211066BF00A931DB /* TestTools.swift */,
153156
6B5B409A211066BF00A931DB /* Info.plist */,
@@ -282,6 +285,7 @@
282285
isa = PBXSourcesBuildPhase;
283286
buildActionMask = 2147483647;
284287
files = (
288+
6B444B3F2165E3D700AEE32B /* ContentEquatableTest.swift in Sources */,
285289
6B5B40A1211066BF00A931DB /* ChangesetTest.swift in Sources */,
286290
6B5B409C211066BF00A931DB /* AlgorithmTest.swift in Sources */,
287291
6B5B40A0211066BF00A931DB /* ElementPathTest.swift in Sources */,

Sources/ContentEquatable.swift

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public protocol ContentEquatable {
1313

1414
public extension ContentEquatable where Self: Equatable {
1515
/// Indicate whether the content of `self` is equals to the content of the given source value.
16-
/// Updates are compared using `==` operator of `Equatable'.
16+
/// Compared using `==` operator of `Equatable'.
1717
///
1818
/// - Parameters:
1919
/// - source: A source value to be compared.
@@ -25,3 +25,28 @@ public extension ContentEquatable where Self: Equatable {
2525
return self == source
2626
}
2727
}
28+
29+
extension Optional: ContentEquatable where Wrapped: ContentEquatable {
30+
/// Indicate whether the content of `self` is equals to the content of the given source value.
31+
/// Returns `true` if both values compared are nil.
32+
/// The result of comparison between nil and non-nil values is `false`.
33+
///
34+
/// - Parameters:
35+
/// - source: An optional source value to be compared.
36+
///
37+
/// - Returns: A Boolean value indicating whether the content of `self` is equals
38+
/// to the content of the given source value.
39+
@inlinable
40+
public func isContentEqual(to source: Wrapped?) -> Bool {
41+
switch (self, source) {
42+
case let (lhs?, rhs?):
43+
return lhs.isContentEqual(to: rhs)
44+
45+
case (.none, .none):
46+
return true
47+
48+
case (.none, .some), (.some, .none):
49+
return false
50+
}
51+
}
52+
}

Tests/ContentEquatableTest.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import XCTest
2+
import DifferenceKit
3+
4+
final class ContentEquatableTestCase: XCTestCase {
5+
func testEquatableValue() {
6+
let value1 = D.a
7+
let value2 = D.a
8+
let value3 = D.b
9+
10+
XCTAssertEqual(value1, value2)
11+
XCTAssertTrue(value1.isContentEqual(to: value2))
12+
13+
XCTAssertNotEqual(value1, value3)
14+
XCTAssertFalse(value1.isContentEqual(to: value3))
15+
}
16+
17+
func testOptionalValue() {
18+
let value1: D? = .a
19+
let value2: D? = .a
20+
let value3: D? = .b
21+
22+
XCTAssertTrue(value1.isContentEqual(to: value2))
23+
XCTAssertFalse(value1.isContentEqual(to: value3))
24+
XCTAssertFalse(value1.isContentEqual(to: nil))
25+
XCTAssertFalse(D?.none.isContentEqual(to: value1))
26+
XCTAssertTrue(D?.none.isContentEqual(to: nil))
27+
}
28+
}

Tests/TestTools.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import DifferenceKit
44
extension Int: Differentiable {}
55
extension String: Differentiable {}
66

7-
enum D: Differentiable, CaseIterable {
7+
enum D: Differentiable, CaseIterable, Equatable {
88
case a, b, c, d, e
99
}
1010

docs/Extensions.html

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
<li class="nav-group-name">
3232
<a href="Extensions.html">Extensions</a>
3333
<ul class="nav-group-tasks">
34+
<li class="nav-group-task">
35+
<a href="Extensions/Optional.html">Optional</a>
36+
</li>
3437
<li class="nav-group-task">
3538
<a href="Extensions/UICollectionView.html">UICollectionView</a>
3639
</li>
@@ -83,6 +86,38 @@ <h1>Extensions</h1>
8386

8487
</section>
8588
<section class="section task-group-section">
89+
<div class="task-group">
90+
<ul>
91+
<li class="item">
92+
<div>
93+
<code>
94+
<a name="/s:Sq"></a>
95+
<a name="//apple_ref/swift/Extension/Optional" class="dashAnchor"></a>
96+
<a class="token" href="#/s:Sq">Optional</a>
97+
</code>
98+
</div>
99+
<div class="height-container">
100+
<div class="pointer-container"></div>
101+
<section class="section">
102+
<div class="pointer"></div>
103+
<div class="abstract">
104+
105+
<a href="Extensions/Optional.html" class="slightly-smaller">See more</a>
106+
</div>
107+
<div class="declaration">
108+
<h4>Declaration</h4>
109+
<div class="language">
110+
<p class="aside-title">Swift</p>
111+
<pre class="highlight swift"><code><span class="kd">@_frozen</span>
112+
<span class="kd">enum</span> <span class="kt">Optional</span><span class="o">&lt;</span><span class="kt">Wrapped</span><span class="o">&gt;</span> <span class="p">:</span> <span class="kt">ExpressibleByNilLiteral</span></code></pre>
113+
114+
</div>
115+
</div>
116+
</section>
117+
</div>
118+
</li>
119+
</ul>
120+
</div>
86121
<div class="task-group">
87122
<ul>
88123
<li class="item">
@@ -144,7 +179,7 @@ <h4>Declaration</h4>
144179
</section>
145180
</section>
146181
<section id="footer">
147-
<p>&copy; 2018 <a class="link" href="https://github.com/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-10-02)</p>
182+
<p>&copy; 2018 <a class="link" href="https://github.com/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-10-04)</p>
148183
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
149184
</section>
150185
</article>

docs/Extensions/Optional.html

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>Optional Extension Reference</title>
5+
<link rel="stylesheet" type="text/css" href="../css/jazzy.css" />
6+
<link rel="stylesheet" type="text/css" href="../css/highlight.css" />
7+
<meta charset='utf-8'>
8+
<script src="../js/jquery.min.js" defer></script>
9+
<script src="../js/jazzy.js" defer></script>
10+
11+
</head>
12+
<body>
13+
<a name="//apple_ref/swift/Extension/Optional" class="dashAnchor"></a>
14+
<a title="Optional Extension Reference"></a>
15+
<header>
16+
<div class="content-wrapper">
17+
<p><a href="../index.html">DifferenceKit Docs</a> (100% documented)</p>
18+
<p class="header-right"><a href="https://github.com/ra1028/DifferenceKit"><img src="../img/gh.png"/>View on GitHub</a></p>
19+
</div>
20+
</header>
21+
<div class="content-wrapper">
22+
<p id="breadcrumbs">
23+
<a href="../index.html">DifferenceKit Reference</a>
24+
<img id="carat" src="../img/carat.png" />
25+
Optional Extension Reference
26+
</p>
27+
</div>
28+
<div class="content-wrapper">
29+
<nav class="sidebar">
30+
<ul class="nav-groups">
31+
<li class="nav-group-name">
32+
<a href="../Extensions.html">Extensions</a>
33+
<ul class="nav-group-tasks">
34+
<li class="nav-group-task">
35+
<a href="../Extensions/Optional.html">Optional</a>
36+
</li>
37+
<li class="nav-group-task">
38+
<a href="../Extensions/UICollectionView.html">UICollectionView</a>
39+
</li>
40+
<li class="nav-group-task">
41+
<a href="../Extensions/UITableView.html">UITableView</a>
42+
</li>
43+
</ul>
44+
</li>
45+
<li class="nav-group-name">
46+
<a href="../Protocols.html">Protocols</a>
47+
<ul class="nav-group-tasks">
48+
<li class="nav-group-task">
49+
<a href="../Protocols/ContentEquatable.html">ContentEquatable</a>
50+
</li>
51+
<li class="nav-group-task">
52+
<a href="../Protocols/Differentiable.html">Differentiable</a>
53+
</li>
54+
<li class="nav-group-task">
55+
<a href="../Protocols/DifferentiableSection.html">DifferentiableSection</a>
56+
</li>
57+
</ul>
58+
</li>
59+
<li class="nav-group-name">
60+
<a href="../Structs.html">Structures</a>
61+
<ul class="nav-group-tasks">
62+
<li class="nav-group-task">
63+
<a href="../Structs/AnyDifferentiable.html">AnyDifferentiable</a>
64+
</li>
65+
<li class="nav-group-task">
66+
<a href="../Structs/ArraySection.html">ArraySection</a>
67+
</li>
68+
<li class="nav-group-task">
69+
<a href="../Structs/Changeset.html">Changeset</a>
70+
</li>
71+
<li class="nav-group-task">
72+
<a href="../Structs/ElementPath.html">ElementPath</a>
73+
</li>
74+
<li class="nav-group-task">
75+
<a href="../Structs/StagedChangeset.html">StagedChangeset</a>
76+
</li>
77+
</ul>
78+
</li>
79+
</ul>
80+
</nav>
81+
<article class="main-content">
82+
<section>
83+
<section class="section">
84+
<h1>Optional</h1>
85+
<div class="declaration">
86+
<div class="language">
87+
<pre class="highlight swift"><code><span class="kd">@_frozen</span>
88+
<span class="kd">enum</span> <span class="kt">Optional</span><span class="o">&lt;</span><span class="kt">Wrapped</span><span class="o">&gt;</span> <span class="p">:</span> <span class="kt">ExpressibleByNilLiteral</span></code></pre>
89+
90+
</div>
91+
</div>
92+
93+
</section>
94+
<section class="section task-group-section">
95+
<div class="task-group">
96+
<ul>
97+
<li class="item">
98+
<div>
99+
<code>
100+
<a name="/s:Sq13DifferenceKitAA16ContentEquatableRzlE02isC5Equal2toSbxSg_tF"></a>
101+
<a name="//apple_ref/swift/Method/isContentEqual(to:)" class="dashAnchor"></a>
102+
<a class="token" href="#/s:Sq13DifferenceKitAA16ContentEquatableRzlE02isC5Equal2toSbxSg_tF">isContentEqual(to:)</a>
103+
</code>
104+
</div>
105+
<div class="height-container">
106+
<div class="pointer-container"></div>
107+
<section class="section">
108+
<div class="pointer"></div>
109+
<div class="abstract">
110+
<p>Indicate whether the content of <code>self</code> is equals to the content of the given source value.
111+
Returns <code>true</code> if both values compared are nil.
112+
The result of comparison between nil and non-nil values is <code>false</code>.</p>
113+
114+
</div>
115+
<div class="declaration">
116+
<h4>Declaration</h4>
117+
<div class="language">
118+
<p class="aside-title">Swift</p>
119+
<pre class="highlight swift"><code><span class="kd">@inlinable</span>
120+
<span class="kd">public</span> <span class="kd">func</span> <span class="nf">isContentEqual</span><span class="p">(</span><span class="n">to</span> <span class="nv">source</span><span class="p">:</span> <span class="kt">Wrapped</span><span class="p">?)</span> <span class="o">-&gt;</span> <span class="kt">Bool</span></code></pre>
121+
122+
</div>
123+
</div>
124+
<div>
125+
<h4>Parameters</h4>
126+
<table class="graybox">
127+
<tbody>
128+
<tr>
129+
<td>
130+
<code>
131+
<em>source</em>
132+
</code>
133+
</td>
134+
<td>
135+
<div>
136+
<p>An optional source value to be compared.</p>
137+
</div>
138+
</td>
139+
</tr>
140+
</tbody>
141+
</table>
142+
</div>
143+
<div>
144+
<h4>Return Value</h4>
145+
<p>A Boolean value indicating whether the content of <code>self</code> is equals
146+
to the content of the given source value.</p>
147+
</div>
148+
</section>
149+
</div>
150+
</li>
151+
</ul>
152+
</div>
153+
</section>
154+
</section>
155+
<section id="footer">
156+
<p>&copy; 2018 <a class="link" href="https://github.com/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-10-04)</p>
157+
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
158+
</section>
159+
</article>
160+
</div>
161+
</body>
162+
</div>
163+
</html>

docs/Extensions/UICollectionView.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
<li class="nav-group-name">
3232
<a href="../Extensions.html">Extensions</a>
3333
<ul class="nav-group-tasks">
34+
<li class="nav-group-task">
35+
<a href="../Extensions/Optional.html">Optional</a>
36+
</li>
3437
<li class="nav-group-task">
3538
<a href="../Extensions/UICollectionView.html">UICollectionView</a>
3639
</li>
@@ -178,7 +181,7 @@ <h4>Parameters</h4>
178181
</section>
179182
</section>
180183
<section id="footer">
181-
<p>&copy; 2018 <a class="link" href="https://github.com/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-10-02)</p>
184+
<p>&copy; 2018 <a class="link" href="https://github.com/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-10-04)</p>
182185
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
183186
</section>
184187
</article>

docs/Extensions/UITableView.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
<li class="nav-group-name">
3232
<a href="../Extensions.html">Extensions</a>
3333
<ul class="nav-group-tasks">
34+
<li class="nav-group-task">
35+
<a href="../Extensions/Optional.html">Optional</a>
36+
</li>
3437
<li class="nav-group-task">
3538
<a href="../Extensions/UICollectionView.html">UICollectionView</a>
3639
</li>
@@ -352,7 +355,7 @@ <h4>Parameters</h4>
352355
</section>
353356
</section>
354357
<section id="footer">
355-
<p>&copy; 2018 <a class="link" href="https://github.com/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-10-02)</p>
358+
<p>&copy; 2018 <a class="link" href="https://github.com/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-10-04)</p>
356359
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
357360
</section>
358361
</article>

docs/Protocols.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
<li class="nav-group-name">
3232
<a href="Extensions.html">Extensions</a>
3333
<ul class="nav-group-tasks">
34+
<li class="nav-group-task">
35+
<a href="Extensions/Optional.html">Optional</a>
36+
</li>
3437
<li class="nav-group-task">
3538
<a href="Extensions/UICollectionView.html">UICollectionView</a>
3639
</li>
@@ -182,7 +185,7 @@ <h4>Declaration</h4>
182185
</section>
183186
</section>
184187
<section id="footer">
185-
<p>&copy; 2018 <a class="link" href="https://github.com/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-10-02)</p>
188+
<p>&copy; 2018 <a class="link" href="https://github.com/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2018-10-04)</p>
186189
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.3</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
187190
</section>
188191
</article>

0 commit comments

Comments
 (0)