<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jon Andersen on Medium]]></title>
        <description><![CDATA[Stories by Jon Andersen on Medium]]></description>
        <link>https://medium.com/@jon.andersen?source=rss-bb9a07bef070------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*X6uJYKU2TKxXn8YF.</url>
            <title>Stories by Jon Andersen on Medium</title>
            <link>https://medium.com/@jon.andersen?source=rss-bb9a07bef070------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 00:15:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jon.andersen/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[RX Progress]]></title>
            <link>https://medium.com/@jon.andersen/rx-progress-b40925e24177?source=rss-bb9a07bef070------2</link>
            <guid isPermaLink="false">https://medium.com/p/b40925e24177</guid>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[reactivecocoa]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Jon Andersen]]></dc:creator>
            <pubDate>Sun, 13 Mar 2016 03:29:41 GMT</pubDate>
            <atom:updated>2016-03-13T03:30:12.768Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I needed to upload some files to a server. I needed to have a progress reported and wanted to make it in a clean RX manner. I explored a few options on how to implement this. The user <em>sprynmr</em> seemed to have encountered the same issue as I. The suggest approach can be found <a href="https://github.com/ReactiveCocoa/ReactiveCocoa/issues/1209#issuecomment-39053959">here</a></p><ol><li>Return a single signal that sends tuples.</li><li>Return two signals.</li><li>Create a class that represents the download process.</li></ol><h4>Return a single signal that sends tuples</h4><p>I found it easier to represent the result as an <a href="https://hackage.haskell.org/package/base-4.8.2.0/docs/Data-Either.html"><strong>Either</strong></a>, with some simplications to avoid having to specify the progress type.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a57fb4c40a96528925178ac1aa5d43e4/href">https://medium.com/media/a57fb4c40a96528925178ac1aa5d43e4/href</a></iframe><p>To download the <em>AVAsset</em> of a video I would do the following</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1b29140fe73ffccb6dca54819137a12/href">https://medium.com/media/d1b29140fe73ffccb6dca54819137a12/href</a></iframe><p>The consumer of this function will now be able to subscribe and recieve events that’s either progress or a final result.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b8bb55a9c708290703f637849bd78be/href">https://medium.com/media/5b8bb55a9c708290703f637849bd78be/href</a></iframe><p>For the <em>onNext</em> method I used the following extension</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0bf90265ffb8fd4672b9d6082213d84a/href">https://medium.com/media/0bf90265ffb8fd4672b9d6082213d84a/href</a></iframe><p>Wrapping the Events like this removes the need to pass an extra function to handle progress. But it falls short when the result needs more transformations. Doing simple operations such as map will yield code that’s much harder to work with.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/276f146888b788249314db567d149637/href">https://medium.com/media/276f146888b788249314db567d149637/href</a></iframe><p>The issue is the switch statement in the map function. We can implement some basic <em>Map</em> &amp; <em>FlatMap</em> functions on our <em>ResultProgress</em> to reduce unwrapping we have to do</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/656028d4d666694b9603248ddd5098d2/href">https://medium.com/media/656028d4d666694b9603248ddd5098d2/href</a></iframe><p>The new mapping function for the <em>SignalProducer</em> would look like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c20a0570845d2824f2bc3ad6ab6b3e88/href">https://medium.com/media/c20a0570845d2824f2bc3ad6ab6b3e88/href</a></iframe><p>Much easier to work with, but I don’t like how you need to call map again inside the map function. I haven’t found a good way to extend the <em>SignalProducers</em> map function to also map the <em>ResultProgress</em>. Have you found a better way to solve this?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b40925e24177" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>