Skip to content

Commit

Permalink
Add map for KeyPath
Browse files Browse the repository at this point in the history
  • Loading branch information
davidask committed Apr 27, 2020
1 parent 050e6e0 commit 8c56228
Show file tree
Hide file tree
Showing 35 changed files with 187 additions and 51 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ If you want to depend on Futures in your project, it's as simple as adding a `d

```swift
dependencies: [
.package(url: "https://github.com/formbound/Futures.git", from: "2.0.0")
.package(url: "https://github.com/formbound/Futures.git", from: "1.6.0")
]
```

Expand Down
22 changes: 17 additions & 5 deletions Sources/Futures/Future.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ public extension Future {
/// - queue: DispatchQueue on which to resolve and return a new future.
/// Defaults to `DispatchQueue.futures`.
/// - callback: A function that will receive the value of this `Future` and return a new `Future<Value>`.
/// Throwing an error in this function will result in the rejection of the returned `Future<Value>`.
/// - value: The fulfilled value of this `Future<Value>`.
/// - Returns: A future that will receive the eventual value.
func flatMap<NewValue>(
Expand Down Expand Up @@ -312,8 +311,6 @@ public extension Future {
/// - queue: DispatchQueue on which to resolve and return a new future.
/// Defaults to `DispatchQueue.futures`.
/// - callback: A function that will receive the error resulting in this `Future<Value>`s rejection.
/// Throwing an error in this function will result in the rejection of the returned `Future<Value>`.
/// and return a new `Future<Value>`.
/// - Returns: A future that will receive the eventual value.
func flatMapIfRejected(
on queue: DispatchQueue = .futures,
Expand Down Expand Up @@ -380,8 +377,7 @@ public extension Future {
/// - Parameters:
/// - queue: DispatchQueue on which to resolve and return a new value.
/// Defaults to `DispatchQueue.futures`.
/// - callback: A function that will receive the value of this `Future` and return a new `Future<Value>`.
/// Throwing an error in this function will result in the rejection of the returned `Future<Value>`.
/// - callback: A function that will receive the value of this `Future` and return a new `Future<Value>`
/// - Returns: A future that will receive the eventual value.
func map<NewValue>(
on queue: DispatchQueue = .futures,
Expand All @@ -396,6 +392,22 @@ public extension Future {
return promise.future
}

/// When the current `Future` is fulfilled, run the provided callback returning a fulfilled value of the
/// `Future<NewValue>` returned by this method.
///
/// - Parameters:
/// - queue: DispatchQueue on which to resolve and return a new value.
/// Defaults to `DispatchQueue.futures`.
/// - keyPath: A `KeyPath<Value, NewValue>` pointing to a value to return on the receiving `Future<Value>`.
/// - Returns: A future that will receive the eventual value.
func map<NewValue>(
_ keyPath: KeyPath<Value, NewValue>,
on queue: DispatchQueue = .futures) -> Future<NewValue> {
map { value in
value[keyPath: keyPath]
}
}

/// When the current `Future` is rejected, run the provided callback returning a fulfilled value of the
/// `Future<NewValue>` returned by this method.
///
Expand Down
2 changes: 1 addition & 1 deletion docs/Classes.html
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
<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>
</section>
</body>
Expand Down
78 changes: 70 additions & 8 deletions docs/Classes/Future.html
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,7 @@ <h4>Parameters</h4>
</td>
<td>
<div>
<p>A function that will receive the value of this <code>Future</code> and return a new <code>Future&lt;Value&gt;</code>.
Throwing an error in this function will result in the rejection of the returned <code>Future&lt;Value&gt;</code>.</p>
<p>A function that will receive the value of this <code>Future</code> and return a new <code>Future&lt;Value&gt;</code>.</p>
</div>
</td>
</tr>
Expand Down Expand Up @@ -646,9 +645,7 @@ <h4>Parameters</h4>
</td>
<td>
<div>
<p>A function that will receive the error resulting in this <code>Future&lt;Value&gt;</code>s rejection.
Throwing an error in this function will result in the rejection of the returned <code>Future&lt;Value&gt;</code>.
and return a new <code>Future&lt;Value&gt;</code>.</p>
<p>A function that will receive the error resulting in this <code>Future&lt;Value&gt;</code>s rejection.</p>
</div>
</td>
</tr>
Expand Down Expand Up @@ -783,8 +780,73 @@ <h4>Parameters</h4>
</td>
<td>
<div>
<p>A function that will receive the value of this <code>Future</code> and return a new <code>Future&lt;Value&gt;</code>.
Throwing an error in this function will result in the rejection of the returned <code>Future&lt;Value&gt;</code>.</p>
<p>A function that will receive the value of this <code>Future</code> and return a new <code>Future&lt;Value&gt;</code></p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div>
<h4>Return Value</h4>
<p>A future that will receive the eventual value.</p>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:7Futures6FutureC3map_2onACyqd__Gs7KeyPathCyxqd__G_So17OS_dispatch_queueCtlF"></a>
<a name="//apple_ref/swift/Method/map(_:on:)" class="dashAnchor"></a>
<a class="token" href="#/s:7Futures6FutureC3map_2onACyqd__Gs7KeyPathCyxqd__G_So17OS_dispatch_queueCtlF">map(_:on:)</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>When the current <code>Future</code> is fulfilled, run the provided callback returning a fulfilled value of the
<code>Future&lt;NewValue&gt;</code> returned by this method.</p>

</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<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>
<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>
<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>

</div>
</div>
<div>
<h4>Parameters</h4>
<table class="graybox">
<tbody>
<tr>
<td>
<code>
<em>queue</em>
</code>
</td>
<td>
<div>
<p>DispatchQueue on which to resolve and return a new value.
Defaults to <code><a href="../Extensions/DispatchQueue.html#/s:So17OS_dispatch_queueC7FuturesE7futuresABvpZ">DispatchQueue.futures</a></code>.</p>
</div>
</td>
</tr>
<tr>
<td>
<code>
<em>keyPath</em>
</code>
</td>
<td>
<div>
<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>
</div>
</td>
</tr>
Expand Down Expand Up @@ -1562,7 +1624,7 @@ <h4>Return Value</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
<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>
</section>
</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/Classes/FutureObserver.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
<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>
</section>
</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/Extensions.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
<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>
</section>
</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/Extensions/DispatchQueue.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
<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>
</section>
</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/Functions.html
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ <h4>Return Value</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
<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>
</section>
</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/Protocols.html
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
<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>
</section>
</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/Protocols/AnyFuture.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
<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>
</section>
</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/Protocols/AnyFutureObserver.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
<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>
</section>
</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/Protocols/PromisesExtended.html
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
<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>
</section>
</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/Structs.html
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
<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>
</section>
</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/Structs/Promise.html
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
<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>
</section>
</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/Structs/Promises.html
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
<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>
</section>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-03-10)</p>
<p>&copy; 2020 <a class="link" href="" target="_blank" rel="external">Formbound</a>. All rights reserved. (Last updated: 2020-04-27)</p>
<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>
</section>
</body>
Expand Down
Loading

0 comments on commit 8c56228

Please sign in to comment.