Skip to content

Commit 8c56228

Browse files
committed
Add map for KeyPath
1 parent 050e6e0 commit 8c56228

35 files changed

+187
-51
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ If you want to depend on Futures in your project, it's as simple as adding a `d
125125

126126
```swift
127127
dependencies: [
128-
.package(url: "https://github.com/formbound/Futures.git", from: "2.0.0")
128+
.package(url: "https://github.com/formbound/Futures.git", from: "1.6.0")
129129
]
130130
```
131131

Sources/Futures/Future.swift

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ public extension Future {
269269
/// - queue: DispatchQueue on which to resolve and return a new future.
270270
/// Defaults to `DispatchQueue.futures`.
271271
/// - callback: A function that will receive the value of this `Future` and return a new `Future<Value>`.
272-
/// Throwing an error in this function will result in the rejection of the returned `Future<Value>`.
273272
/// - value: The fulfilled value of this `Future<Value>`.
274273
/// - Returns: A future that will receive the eventual value.
275274
func flatMap<NewValue>(
@@ -312,8 +311,6 @@ public extension Future {
312311
/// - queue: DispatchQueue on which to resolve and return a new future.
313312
/// Defaults to `DispatchQueue.futures`.
314313
/// - callback: A function that will receive the error resulting in this `Future<Value>`s rejection.
315-
/// Throwing an error in this function will result in the rejection of the returned `Future<Value>`.
316-
/// and return a new `Future<Value>`.
317314
/// - Returns: A future that will receive the eventual value.
318315
func flatMapIfRejected(
319316
on queue: DispatchQueue = .futures,
@@ -380,8 +377,7 @@ public extension Future {
380377
/// - Parameters:
381378
/// - queue: DispatchQueue on which to resolve and return a new value.
382379
/// Defaults to `DispatchQueue.futures`.
383-
/// - callback: A function that will receive the value of this `Future` and return a new `Future<Value>`.
384-
/// Throwing an error in this function will result in the rejection of the returned `Future<Value>`.
380+
/// - callback: A function that will receive the value of this `Future` and return a new `Future<Value>`
385381
/// - Returns: A future that will receive the eventual value.
386382
func map<NewValue>(
387383
on queue: DispatchQueue = .futures,
@@ -396,6 +392,22 @@ public extension Future {
396392
return promise.future
397393
}
398394

395+
/// When the current `Future` is fulfilled, run the provided callback returning a fulfilled value of the
396+
/// `Future<NewValue>` returned by this method.
397+
///
398+
/// - Parameters:
399+
/// - queue: DispatchQueue on which to resolve and return a new value.
400+
/// Defaults to `DispatchQueue.futures`.
401+
/// - keyPath: A `KeyPath<Value, NewValue>` pointing to a value to return on the receiving `Future<Value>`.
402+
/// - Returns: A future that will receive the eventual value.
403+
func map<NewValue>(
404+
_ keyPath: KeyPath<Value, NewValue>,
405+
on queue: DispatchQueue = .futures) -> Future<NewValue> {
406+
map { value in
407+
value[keyPath: keyPath]
408+
}
409+
}
410+
399411
/// When the current `Future` is rejected, run the provided callback returning a fulfilled value of the
400412
/// `Future<NewValue>` returned by this method.
401413
///

docs/Classes.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ <h4>Declaration</h4>
247247
</article>
248248
</div>
249249
<section class="footer">
250-
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
250+
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
251251
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
252252
</section>
253253
</body>

docs/Classes/Future.html

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,7 @@ <h4>Parameters</h4>
562562
</td>
563563
<td>
564564
<div>
565-
<p>A function that will receive the value of this <code>Future</code> and return a new <code>Future&lt;Value&gt;</code>.
566-
Throwing an error in this function will result in the rejection of the returned <code>Future&lt;Value&gt;</code>.</p>
565+
<p>A function that will receive the value of this <code>Future</code> and return a new <code>Future&lt;Value&gt;</code>.</p>
567566
</div>
568567
</td>
569568
</tr>
@@ -646,9 +645,7 @@ <h4>Parameters</h4>
646645
</td>
647646
<td>
648647
<div>
649-
<p>A function that will receive the error resulting in this <code>Future&lt;Value&gt;</code>s rejection.
650-
Throwing an error in this function will result in the rejection of the returned <code>Future&lt;Value&gt;</code>.
651-
and return a new <code>Future&lt;Value&gt;</code>.</p>
648+
<p>A function that will receive the error resulting in this <code>Future&lt;Value&gt;</code>s rejection.</p>
652649
</div>
653650
</td>
654651
</tr>
@@ -783,8 +780,73 @@ <h4>Parameters</h4>
783780
</td>
784781
<td>
785782
<div>
786-
<p>A function that will receive the value of this <code>Future</code> and return a new <code>Future&lt;Value&gt;</code>.
787-
Throwing an error in this function will result in the rejection of the returned <code>Future&lt;Value&gt;</code>.</p>
783+
<p>A function that will receive the value of this <code>Future</code> and return a new <code>Future&lt;Value&gt;</code></p>
784+
</div>
785+
</td>
786+
</tr>
787+
</tbody>
788+
</table>
789+
</div>
790+
<div>
791+
<h4>Return Value</h4>
792+
<p>A future that will receive the eventual value.</p>
793+
</div>
794+
</section>
795+
</div>
796+
</li>
797+
<li class="item">
798+
<div>
799+
<code>
800+
<a name="/s:7Futures6FutureC3map_2onACyqd__Gs7KeyPathCyxqd__G_So17OS_dispatch_queueCtlF"></a>
801+
<a name="//apple_ref/swift/Method/map(_:on:)" class="dashAnchor"></a>
802+
<a class="token" href="#/s:7Futures6FutureC3map_2onACyqd__Gs7KeyPathCyxqd__G_So17OS_dispatch_queueCtlF">map(_:on:)</a>
803+
</code>
804+
</div>
805+
<div class="height-container">
806+
<div class="pointer-container"></div>
807+
<section class="section">
808+
<div class="pointer"></div>
809+
<div class="abstract">
810+
<p>When the current <code>Future</code> is fulfilled, run the provided callback returning a fulfilled value of the
811+
<code>Future&lt;NewValue&gt;</code> returned by this method.</p>
812+
813+
</div>
814+
<div class="declaration">
815+
<h4>Declaration</h4>
816+
<div class="language">
817+
<p class="aside-title">Swift</p>
818+
<pre class="highlight swift"><code><span class="kd">func</span> <span class="n">map</span><span class="o">&lt;</span><span class="kt">NewValue</span><span class="o">&gt;</span><span class="p">(</span>
819+
<span class="n">_</span> <span class="nv">keyPath</span><span class="p">:</span> <span class="kt">KeyPath</span><span class="o">&lt;</span><span class="kt">Value</span><span class="p">,</span> <span class="kt">NewValue</span><span class="o">&gt;</span><span class="p">,</span>
820+
<span class="n">on</span> <span class="nv">queue</span><span class="p">:</span> <span class="kt">DispatchQueue</span> <span class="o">=</span> <span class="o">.</span><span class="n">futures</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">Future</span><span class="o">&lt;</span><span class="kt">NewValue</span><span class="o">&gt;</span></code></pre>
821+
822+
</div>
823+
</div>
824+
<div>
825+
<h4>Parameters</h4>
826+
<table class="graybox">
827+
<tbody>
828+
<tr>
829+
<td>
830+
<code>
831+
<em>queue</em>
832+
</code>
833+
</td>
834+
<td>
835+
<div>
836+
<p>DispatchQueue on which to resolve and return a new value.
837+
Defaults to <code><a href="../Extensions/DispatchQueue.html#/s:So17OS_dispatch_queueC7FuturesE7futuresABvpZ">DispatchQueue.futures</a></code>.</p>
838+
</div>
839+
</td>
840+
</tr>
841+
<tr>
842+
<td>
843+
<code>
844+
<em>keyPath</em>
845+
</code>
846+
</td>
847+
<td>
848+
<div>
849+
<p>A <code>KeyPath&lt;Value, NewValue&gt;</code> pointing to a value to return on the receiving <code>Future&lt;Value&gt;</code>.</p>
788850
</div>
789851
</td>
790852
</tr>
@@ -1562,7 +1624,7 @@ <h4>Return Value</h4>
15621624
</article>
15631625
</div>
15641626
<section class="footer">
1565-
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
1627+
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
15661628
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
15671629
</section>
15681630
</body>

docs/Classes/FutureObserver.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ <h4>Declaration</h4>
199199
</article>
200200
</div>
201201
<section class="footer">
202-
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
202+
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
203203
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
204204
</section>
205205
</body>

docs/Extensions.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ <h4>Declaration</h4>
156156
</article>
157157
</div>
158158
<section class="footer">
159-
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
159+
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
160160
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
161161
</section>
162162
</body>

docs/Extensions/DispatchQueue.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ <h4>Declaration</h4>
161161
</article>
162162
</div>
163163
<section class="footer">
164-
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
164+
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
165165
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
166166
</section>
167167
</body>

docs/Functions.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ <h4>Return Value</h4>
285285
</article>
286286
</div>
287287
<section class="footer">
288-
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
288+
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
289289
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
290290
</section>
291291
</body>

docs/Protocols.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ <h4>Declaration</h4>
248248
</article>
249249
</div>
250250
<section class="footer">
251-
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
251+
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
252252
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
253253
</section>
254254
</body>

docs/Protocols/AnyFuture.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ <h4>Declaration</h4>
216216
</article>
217217
</div>
218218
<section class="footer">
219-
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
219+
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
220220
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
221221
</section>
222222
</body>

docs/Protocols/AnyFutureObserver.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ <h4>Declaration</h4>
162162
</article>
163163
</div>
164164
<section class="footer">
165-
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
165+
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
166166
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
167167
</section>
168168
</body>

docs/Protocols/PromisesExtended.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ <h4>Declaration</h4>
230230
</article>
231231
</div>
232232
<section class="footer">
233-
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
233+
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
234234
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
235235
</section>
236236
</body>

docs/Structs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ <h4>Declaration</h4>
226226
</article>
227227
</div>
228228
<section class="footer">
229-
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
229+
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
230230
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
231231
</section>
232232
</body>

docs/Structs/Promise.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ <h4>Declaration</h4>
406406
</article>
407407
</div>
408408
<section class="footer">
409-
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
409+
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
410410
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
411411
</section>
412412
</body>

docs/Structs/Promises.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ <h4>Declaration</h4>
164164
</article>
165165
</div>
166166
<section class="footer">
167-
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
167+
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
168168
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
169169
</section>
170170
</body>

docs/docsets/.docset/Contents/Resources/Documents/Classes.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ <h4>Declaration</h4>
247247
</article>
248248
</div>
249249
<section class="footer">
250-
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
250+
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
251251
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
252252
</section>
253253
</body>

0 commit comments

Comments
 (0)