<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><description>I am an iOS Developer working in San Francisco, CA</description><title>Javier Soto</title><generator>Tumblr (3.0; @javisoto)</generator><link>https://javisoto.tumblr.com/</link><item><title>“Back to the Futures” talk at Swift Summit in London</title><description>&lt;p&gt;This past March I gave a talk at the first &lt;a href="https://www.swiftsummit.com/"&gt;Swift Summit&lt;/a&gt; in London. The video along with the slides has been posted by &lt;a href="https://realm.io/"&gt;Realm&lt;/a&gt;, go check it out!&lt;/p&gt;&lt;p&gt;&lt;a href="http://realm.io/news/swift-summit-javier-soto-futures/"&gt;&lt;/a&gt;&lt;/p&gt;&lt;a href="http://realm.io/news/swift-summit-javier-soto-futures/"&gt;&lt;figure class="tmblr-full" data-orig-height="297" data-orig-width="540" data-orig-src="https://64.media.tumblr.com/9727627244bf9f9fb16f9c28152c65f9/tumblr_inline_noo3y43FU91r4sinw_540.png"&gt;&lt;img src="https://64.media.tumblr.com/8c7a91e0d7f087b3973900a4292e6af9/tumblr_inline_pedez4og5m1r4sinw_540.png" alt="" data-orig-height="297" data-orig-width="540" data-orig-src="https://64.media.tumblr.com/9727627244bf9f9fb16f9c28152c65f9/tumblr_inline_noo3y43FU91r4sinw_540.png"/&gt;&lt;/figure&gt;&lt;/a&gt;&lt;p&gt;&lt;a href="http://realm.io/news/swift-summit-javier-soto-futures/"&gt;http://realm.io/news/swift-summit-javier-soto-futures/&lt;/a&gt;&lt;/p&gt;</description><link>https://javisoto.tumblr.com/post/119471144169</link><guid>https://javisoto.tumblr.com/post/119471144169</guid><pubDate>Wed, 20 May 2015 14:36:01 -0700</pubDate></item><item><title>Featured in an article published on El País</title><description>&lt;p&gt;Today my brother &lt;a href="http://www.twitter.com/NachoSoto"&gt;Nacho&lt;/a&gt; and I had the pleasure to be featured in an article in one of the biggest newspapers in our home country, Spain.&lt;/p&gt;&lt;figure class="tmblr-full" data-orig-height="779" data-orig-width="590"&gt;&lt;img src="https://64.media.tumblr.com/97732e11c3b112b4a50d5a626695fd4d/tumblr_inline_no02abhLoL1r4sinw_540.png" data-orig-height="779" data-orig-width="590"/&gt;&lt;/figure&gt;&lt;p&gt;&lt;a href="http://tecnologia.elpais.com/tecnologia/2015/05/07/actualidad/1430960436_222805.html"&gt;http://tecnologia.elpais.com/tecnologia/2015/05/07/actualidad/1430960436_222805.html&lt;/a&gt;&lt;/p&gt;</description><link>https://javisoto.tumblr.com/post/118393198004</link><guid>https://javisoto.tumblr.com/post/118393198004</guid><pubDate>Thu, 07 May 2015 14:55:53 -0700</pubDate></item><item><title>Functor and Monad in Swift</title><description>&lt;p&gt;I have been trying to teach myself Functional Programming since late 2013. Many of the concepts are very daunting because of their somewhat academic nature.&lt;/p&gt;&lt;p&gt;Since I&amp;rsquo;m obviously not an expert, I intend this to be a very practical post. You will find many posts trying to explain what a Monad is, &lt;a href="http://blog.plover.com/prog/burritos.html"&gt;some of them trying a bit too hard to come up with similes&lt;/a&gt;, but hopefully the sample code here will illustrate some of the concepts better.&lt;/p&gt;&lt;p&gt;It wasn&amp;rsquo;t until recently that I finally could say that I got what Monad means. Let&amp;rsquo;s explore why this concept even exists, and how it can help you when writing Swift code.&lt;/p&gt;&lt;h2&gt;&lt;a href="https://github.com/JaviSoto/Blog-Posts/blob/master/Functor%20and%20Monad%20in%20Swift/FunctorAndMonad.md#map"&gt;&lt;/a&gt;Map&lt;/h2&gt;&lt;p&gt;One of the first things that we got to see at the 2014 WWDC with the introduction of Swift was that we could use the &lt;code&gt;map&lt;/code&gt; function with the collection types. Let&amp;rsquo;s focus on Swift&amp;rsquo;s &lt;code&gt;Array&lt;/code&gt;.&lt;/p&gt;&lt;pre&gt;let numbers = [1, 2, 3]

let doubledNumbers = numbers.map { $0 * 2 }
// doubledNumbers: 2, 4, 6&lt;/pre&gt;&lt;p&gt;The benefit of this pattern is that we can very clearly express the transformation that we&amp;rsquo;re trying to apply on the list of elements (in this case, doubling their value). Compare this with the imperative approach:&lt;/p&gt;&lt;pre&gt;var doubledImperative: [Int] = []
for number in numbers {
    doubledImperative.append(number * 2)
}
// doubledImperative: 2, 4, 6&lt;/pre&gt;&lt;p&gt;It&amp;rsquo;s not about solving it in a one-liner vs 3 lines, but with the former concise implementation, there&amp;rsquo;s a significantly higher signal-to-noise ratio. &lt;code&gt;map&lt;/code&gt; allows us to express what we want to achieve, rather than how this is implemented. This eases our ability to reason about code when we read it.&lt;/p&gt;&lt;p&gt;But &lt;code&gt;map&lt;/code&gt; doesn&amp;rsquo;t only make sense on &lt;code&gt;Array&lt;/code&gt;. &lt;code&gt;map&lt;/code&gt; is a higher-order function that can be implemented on just any container type. That is, any type that, one way or another, wraps one or multiple values inside.&lt;/p&gt;&lt;p&gt;Let&amp;rsquo;s look at another example: &lt;code&gt;Optional&lt;/code&gt;. &lt;code&gt;Optional&lt;/code&gt; is a container type that wraps a value, or the absence of it.&lt;/p&gt;&lt;pre&gt;let number = Optional(815)

let transformedNumber = number.map { $0 * 2 }.map { $0 % 2 == 0 }
// transformedNumber: Optional.Some(true)&lt;/pre&gt;&lt;p&gt;The benefit of &lt;code&gt;map&lt;/code&gt; in &lt;code&gt;Optional&lt;/code&gt; is that it will handle nil values for us. If we&amp;rsquo;re trying to operate on a value that may be &lt;code&gt;nil&lt;/code&gt;, we can use &lt;code&gt;Optional.map&lt;/code&gt; to apply those transformations, and end up with &lt;code&gt;nil&lt;/code&gt; if the original value was &lt;code&gt;nil&lt;/code&gt;, but without having to resort to nested &lt;code&gt;if let&lt;/code&gt; to unwrap the optional.&lt;/p&gt;&lt;pre&gt;let nilNumber: Int? = .None

let transformedNilNumber = nilNumber.map { $0 * 2 }.map { $0 % 2 == 0 }
// transformedNilNumber: None&lt;/pre&gt;&lt;p&gt;From this we can extrapolate that &lt;code&gt;map&lt;/code&gt;, when implemented on different container types, can have slightly different behaviors, depending on the semantics of that type. For example, it only makes sense to transform the value inside an &lt;code&gt;Optional&lt;/code&gt; when there&amp;rsquo;s actually a value inside.&lt;/p&gt;&lt;p&gt;This is the general signature of a &lt;code&gt;map&lt;/code&gt; method, when implemented on a &lt;code&gt;Container&lt;/code&gt; type, that wraps values of type &lt;code&gt;T&lt;/code&gt;:&lt;/p&gt;&lt;pre&gt;func map&amp;lt;U&amp;gt;(transformFunction: T -&amp;gt; U) -&amp;gt; Container&amp;lt;U&amp;gt;&lt;/pre&gt;&lt;p&gt;Let&amp;rsquo;s analyze that signature by looking at the types. &lt;code&gt;T&lt;/code&gt; is the type of elements in the current container, &lt;code&gt;U&lt;/code&gt; will be the type of the elements in the container that will be returned. This allows us to, for example, map an array of strings, to an array of &lt;code&gt;Int&lt;/code&gt;s that contains the lengths of each of the &lt;code&gt;String&lt;/code&gt;s in the original array.&lt;/p&gt;&lt;p&gt;We provide a function that takes a &lt;code&gt;T&lt;/code&gt; value, and returns a value of type &lt;code&gt;U&lt;/code&gt;. &lt;code&gt;map&lt;/code&gt; will then use this function to create another &lt;code&gt;Container&lt;/code&gt; instance, where the original values are replaced by the ones returned by the &lt;code&gt;transformFunction&lt;/code&gt;.&lt;/p&gt;&lt;h2&gt;&lt;a href="https://github.com/JaviSoto/Blog-Posts/blob/master/Functor%20and%20Monad%20in%20Swift/FunctorAndMonad.md#implementing-map-with-our-own-type"&gt;&lt;/a&gt;Implementing &lt;code&gt;map&lt;/code&gt; with our own type&lt;/h2&gt;&lt;p&gt;Let&amp;rsquo;s implement our own container type. A &lt;code&gt;Result&lt;/code&gt; enum is a pattern that you will see in a lot of open source Swift code today. &lt;a href="https://gist.github.com/andymatuschak/2b311461caf740f5726f#comment-1364205"&gt;This brings several benefits to an API when used instead of the old Obj-C NSError-by-reference argument&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;We could define it like this:&lt;/p&gt;&lt;pre&gt;enum Result&amp;lt;T&amp;gt; {
    case Value(T)
    case Error(NSError)
}&lt;/pre&gt;&lt;p&gt;This is an implementation of a type known as &lt;code&gt;Either&lt;/code&gt; in some programming languages. Only in this case we&amp;rsquo;re forcing one of the types to be an &lt;code&gt;NSError&lt;/code&gt; instead of being generic, since we&amp;rsquo;re going to use it to report the result of an operation.&lt;/p&gt;&lt;p&gt;Conceptually, &lt;code&gt;Result&lt;/code&gt; is very similar to &lt;code&gt;Optional&lt;/code&gt;: it wraps a value of an arbitrary type, that may or may not be present. In this case, however, it may additional tell us why the value is not there.&lt;/p&gt;&lt;p&gt;To see an example, let&amp;rsquo;s implement a function that reads the contents of a file and returns the result as a &lt;code&gt;Result&lt;/code&gt; object:&lt;/p&gt;&lt;pre&gt;func dataWithContentsOfFile(file: String, encoding: NSStringEncoding) -&amp;gt; Result&amp;lt;NSData&amp;gt; {
    var error: NSError?

    if let data = NSData(contentsOfFile: file, options: .allZeros, error: &amp;amp;error) {
        return .Value(data)
    }
    else {
        return .Error(error!)
    }
}&lt;/pre&gt;&lt;p&gt;Easy enough. This function will return either an &lt;code&gt;NSData&lt;/code&gt; object, or an &lt;code&gt;NSError&lt;/code&gt; in case the file can&amp;rsquo;t be read.&lt;/p&gt;&lt;p&gt;Like we did before, we may want to apply some transformation to the read value. However, like in the case before, we would need to check that we have a value every step of the way, which may result in ugly nested &lt;code&gt;if let&lt;/code&gt;s or &lt;code&gt;switch&lt;/code&gt; statements. Let&amp;rsquo;s leverage &lt;code&gt;map&lt;/code&gt; like we did before. In this case, we will only want to apply such transformation if we have a value. If we don&amp;rsquo;t, we can simply pass the same error through.&lt;/p&gt;&lt;p&gt;Imagine that we wanted to read a file with string contents. We would get an &lt;code&gt;NSData&lt;/code&gt;, that then we need to transform into a &lt;code&gt;String&lt;/code&gt;. Then say that we want to turn it into uppercase:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;NSData -&amp;gt; String -&amp;gt; String
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;We can do this with a series of &lt;code&gt;map&lt;/code&gt; transformations (we&amp;rsquo;ll discuss the implementation of &lt;code&gt;map&lt;/code&gt; later):&lt;/p&gt;&lt;pre&gt;let data: Result&amp;lt;NSData&amp;gt; = dataWithContentsOfFile(path, NSUTF8StringEncoding)

let uppercaseContents: Result&amp;lt;String&amp;gt; = data.map { NSString(data: $0, encoding: NSUTF8StringEncoding)! }.map { $0.uppercaseString }&lt;/pre&gt;&lt;p&gt;Similar to the early example with &lt;code&gt;map&lt;/code&gt; on &lt;code&gt;Array&lt;/code&gt;s, this code is a lot more expressive. It simply declares what we want to accomplish, with no boilerplate.&lt;/p&gt;&lt;p&gt;In comparison, this is what the above code would look like without the use of &lt;code&gt;map&lt;/code&gt;:&lt;/p&gt;&lt;pre&gt;let data: Result&amp;lt;NSData&amp;gt; = dataWithContentsOfFile(path, NSUTF8StringEncoding)

var stringContents: String?

switch data {
    case let .Value(value):
        stringContents = NSString(data: value, encoding: NSUTF8StringEncoding)
    case let .Error(error):
        break
}

let uppercaseContents: String? = stringContents?.uppercaseString&lt;/pre&gt;&lt;p&gt;How would &lt;code&gt;Result.map&lt;/code&gt; be implemented? Let&amp;rsquo;s take a look:&lt;/p&gt;&lt;pre&gt;extension Result {
    func map&amp;lt;U&amp;gt;(f: T -&amp;gt; U) -&amp;gt; Result&amp;lt;U&amp;gt; {
        switch self {
            case let .Value(value):
                return Result&amp;lt;U&amp;gt;.Value(f(value))
            case let .Error(error):
                return Result&amp;lt;U&amp;gt;.Error(error)
        }
    }
}&lt;/pre&gt;&lt;p&gt;Again, the transformation function &lt;code&gt;f&lt;/code&gt; takes a value of type &lt;code&gt;T&lt;/code&gt; (in the above example, &lt;code&gt;NSData&lt;/code&gt;) and returns a value of type &lt;code&gt;U&lt;/code&gt; (&lt;code&gt;String&lt;/code&gt;). After calling &lt;code&gt;map&lt;/code&gt;, we&amp;rsquo;ll get a &lt;code&gt;Result&amp;lt;U&amp;gt;&lt;/code&gt;(&lt;code&gt;Result&amp;lt;String&amp;gt;&lt;/code&gt;) from an initial &lt;code&gt;Result&amp;lt;T&amp;gt;&lt;/code&gt; (&lt;code&gt;Result&amp;lt;NSData&amp;gt;&lt;/code&gt;). We only call &lt;code&gt;f&lt;/code&gt; whenever we start with a value, and we simply return another &lt;code&gt;Result&lt;/code&gt; with the same error otherwise.&lt;/p&gt;&lt;h2&gt;&lt;a href="https://github.com/JaviSoto/Blog-Posts/blob/master/Functor%20and%20Monad%20in%20Swift/FunctorAndMonad.md#functors"&gt;&lt;/a&gt;Functors&lt;/h2&gt;&lt;p&gt;We&amp;rsquo;ve seen what &lt;code&gt;map&lt;/code&gt; can do when implemented on a container type, like &lt;code&gt;Optional&lt;/code&gt;, &lt;code&gt;Array&lt;/code&gt; or &lt;code&gt;Result&lt;/code&gt;. To recap, it allows us to get a new container, where the value(s) wrapped inside are transformed according to a function. So what&amp;rsquo;s a Functor you may ask? A Functor is any type that implements &lt;code&gt;map&lt;/code&gt;. That&amp;rsquo;s the whole story.&lt;/p&gt;&lt;p&gt;Once you know what a functor is, we can talk about some types like &lt;code&gt;Dictionary&lt;/code&gt; or even closures, and by saying that they&amp;rsquo;re functors, you will immediately know of something you can do with them.&lt;/p&gt;&lt;h2&gt;&lt;a href="https://github.com/JaviSoto/Blog-Posts/blob/master/Functor%20and%20Monad%20in%20Swift/FunctorAndMonad.md#monads"&gt;&lt;/a&gt;Monads&lt;/h2&gt;&lt;p&gt;In the earlier example, we used the transformation function to return another value, but what if we wanted to use it to return a new &lt;code&gt;Result&lt;/code&gt; object? Put another way, what if the transformation operation that we&amp;rsquo;re passing to &lt;code&gt;map&lt;/code&gt; can fail with an error as well? Let&amp;rsquo;s look at what the types would look like.&lt;/p&gt;&lt;pre&gt;func map&amp;lt;U&amp;gt;(f: T -&amp;gt; U) -&amp;gt; Result&amp;lt;U&amp;gt;&lt;/pre&gt;&lt;p&gt;In our example, &lt;code&gt;T&lt;/code&gt; is an &lt;code&gt;NSData&lt;/code&gt; that we&amp;rsquo;re converting into &lt;code&gt;U&lt;/code&gt;, a &lt;code&gt;Result&amp;lt;String&amp;gt;&lt;/code&gt;. So let&amp;rsquo;s replace that in the signature:&lt;/p&gt;&lt;pre&gt;func map(f: NSData -&amp;gt; Result&amp;lt;String&amp;gt;) -&amp;gt; Result&amp;lt;Result&amp;lt;String&amp;gt;&amp;gt;&lt;/pre&gt;&lt;p&gt;Notice the nested &lt;code&gt;Result&lt;/code&gt;s in the return type. This is probably not what we&amp;rsquo;ll want. But it&amp;rsquo;s OK. We can implement a function that takes the nested &lt;code&gt;Result&lt;/code&gt;, and flattens it into a simple&lt;code&gt;Result&lt;/code&gt;:&lt;/p&gt;&lt;pre&gt;extension Result {
    static func flatten&amp;lt;T&amp;gt;(result: Result&amp;lt;Result&amp;lt;T&amp;gt;&amp;gt;) -&amp;gt; Result&amp;lt;T&amp;gt; {
        switch result {
            case let .Value(innerResult):
                return innerResult
            case let .Error(error):
                return Result&amp;lt;T&amp;gt;.Error(error)
        }
    }
}&lt;/pre&gt;&lt;p&gt;This &lt;code&gt;flatten&lt;/code&gt; function takes a nested &lt;code&gt;Result&lt;/code&gt; with a &lt;code&gt;T&lt;/code&gt; inside, and return a single &lt;code&gt;Result&amp;lt;T&amp;gt;&lt;/code&gt; simply by extracting the inner object inside the &lt;code&gt;Value&lt;/code&gt;, or the &lt;code&gt;Error&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;A &lt;code&gt;flatten&lt;/code&gt; function can be found in other contexts. For example, one can &lt;code&gt;flatten&lt;/code&gt; an array of arrays into a contiguous, one-dimensional array.&lt;/p&gt;&lt;p&gt;With this, we can implement our &lt;code&gt;Result&amp;lt;NSData&amp;gt; -&amp;gt; Result&amp;lt;String&amp;gt;&lt;/code&gt; transformation by combining &lt;code&gt;map&lt;/code&gt; and &lt;code&gt;flatten&lt;/code&gt;:&lt;/p&gt;&lt;pre&gt;let stringResult = Result&amp;lt;String&amp;gt;.flatten(data.map { (data: NSData) -&amp;gt; (Result&amp;lt;String&amp;gt;) in
    if let string = NSString(data: data, encoding: NSUTF8StringEncoding) {
        return Result.Value(string)
    }
    else {
        return Result&amp;lt;String&amp;gt;.Error(NSError(domain: "com.javisoto.es.error_domain", code: JSErrorCodeInvalidStringData, userInfo: nil))
    }
})&lt;/pre&gt;&lt;p&gt;This is so common, that you will find this defined in many places as &lt;code&gt;flatMap&lt;/code&gt; or &lt;code&gt;flattenMap&lt;/code&gt;, which we could implement for &lt;code&gt;Result&lt;/code&gt; like this:&lt;/p&gt;&lt;pre&gt;extension Result {
    func flatMap&amp;lt;U&amp;gt;(f: T -&amp;gt; Result&amp;lt;U&amp;gt;) -&amp;gt; Result&amp;lt;U&amp;gt; {
        return Result.flatten(map(f))
    }
}&lt;/pre&gt;&lt;p&gt;And with that, we turned our &lt;code&gt;Result&lt;/code&gt; type into a Monad! A Monad is a type of Functor. A type which, along with &lt;code&gt;map&lt;/code&gt;, implements a &lt;code&gt;flatMap&lt;/code&gt; function (sometimes also known as&lt;code&gt;bind&lt;/code&gt;) with a signature similar to the one we&amp;rsquo;ve seen here. Container types like the ones we presented here are usually Monads, but you will also see that pattern for example in types that encapsulate deferred computation, like &lt;code&gt;Signal&lt;/code&gt; or &lt;code&gt;Future&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;The words Functor and Monad come from category theory, with which I&amp;rsquo;m not familiar at all. However, there&amp;rsquo;s value in having names to refer to these concepts. Computer scientists love to come up with names for things. But it&amp;rsquo;s those names that allow us to refer to abstract concepts (some extremely abstract, like Monad), and immediately know what we mean (of course, assuming we have the previous knowledge of their meaning). We get the same benefit out of sharing names for things like design patterns (decorator, factory&amp;hellip;).&lt;/p&gt;&lt;p&gt;It took me a very long time to assimilate all the ideas in this blog post, so if you&amp;rsquo;re not familiar with any of this I don&amp;rsquo;t expect you to finish reading this and immediately understand it. However, I encourage you to create an Xcode playground and try to come up with the implementation for &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;flatten&lt;/code&gt; and &lt;code&gt;flatMap&lt;/code&gt; for &lt;code&gt;Result&lt;/code&gt; or a similar container type (perhaps try with &lt;code&gt;Optional&lt;/code&gt; or even &lt;code&gt;Array&lt;/code&gt;), and use some sample values to play with them.&lt;/p&gt;&lt;p&gt;And next time you hear the words Functor or Monad, don&amp;rsquo;t be scared :) They&amp;rsquo;re simply design patterns to describe common operations that we can perform on different types.&lt;/p&gt;&lt;p&gt;Open source version of the article, where you can create an issue to ask a question or open pull requests: &lt;a href="https://github.com/JaviSoto/Blog-Posts/blob/master/Functor%20and%20Monad%20in%20Swift/FunctorAndMonad.md"&gt;https://github.com/JaviSoto/Blog-Posts/blob/master/Functor%20and%20Monad%20in%20Swift/FunctorAndMonad.md&lt;/a&gt;&lt;/p&gt;</description><link>https://javisoto.tumblr.com/post/106875422394</link><guid>https://javisoto.tumblr.com/post/106875422394</guid><pubDate>Thu, 01 Jan 2015 21:39:00 -0800</pubDate></item><item><title>Most influential Latinos in Tech 2014</title><description>&lt;a href="http://www.cnet.com/es/imagenes/20-latinos-mas-influyentes-industria-tecnologia-2014-fotos/"&gt;Most influential Latinos in Tech 2014&lt;/a&gt;: &lt;p&gt;Somehow I’m among the most influential Latinos in tech by “CNET en Español” along with people like Eddie Cue and Matias Duarte.&lt;/p&gt;</description><link>https://javisoto.tumblr.com/post/99016779129</link><guid>https://javisoto.tumblr.com/post/99016779129</guid><pubDate>Thu, 02 Oct 2014 18:22:00 -0700</pubDate></item><item><title>Interviewed by "CNET en Español"</title><description>&lt;p&gt;I was interviewed by CNET at Pebble HQ. I answer questions about things like my path to Silicon Valley or my opinion on the evolution of wearable devices.&lt;/p&gt;

&lt;p&gt;&lt;iframe frameborder="0" height="360" src="//www.youtube.com/embed/S-K-OSgCcfA" width="640"&gt;&lt;/iframe&gt;&lt;/p&gt;</description><link>https://javisoto.tumblr.com/post/91304979189</link><guid>https://javisoto.tumblr.com/post/91304979189</guid><pubDate>Wed, 09 Jul 2014 18:02:50 -0700</pubDate></item><item><title>ReactiveCocoa</title><description>&lt;p&gt;A lot is being written these days about ReactiveCocoa and the paradigms it introduces. In my opinion, there are only two sides giving their opinion: the ones that know a lot about it and are therefore obviously biased, and the ones that refuse to learn it.&lt;/p&gt;
&lt;p&gt;I decided to write something myself because I think I&amp;rsquo;m right in the middle. A few months ago I knew nothing about it, and now I know enough to want to use it every day. I hope that by not being an expert, I can actual introduce a few really simple ideas in a much easier way to pick up by newcomers, to show why I think ReactiveCocoa is an incredibly powerful tool to help us write better, cleaner, and more maintainable code.&lt;/p&gt;
&lt;h3&gt;&lt;a class="anchor" href="https://gist.github.com/indragiek/9105830/a39f9de510f422737226f30f568fee5fa015b24f#its-signals-all-the-way-down" name="its-signals-all-the-way-down" rel="noreferrer"&gt;&lt;/a&gt;It&amp;rsquo;s signals all the way down&lt;/h3&gt;
&lt;p&gt;The base of &lt;strong&gt;everything&lt;/strong&gt; that happens in ReactiveCocoa is signals. I&amp;rsquo;m going to try to explain what they &lt;em&gt;represent&lt;/em&gt; and why they fit in the way we think about what happens on an app. A lot of the things you may read about Functional Reactive Programming end up confusing you when they introduce more advanced FP operators, etc. So let&amp;rsquo;s avoid that.&lt;/p&gt;
&lt;p&gt;What is a signal? Think of it as a pipe that carries values. This flow of values is actually present everywhere in our apps when you think about it: the data downloaded from the network, the Boolean value &amp;ldquo;is the user logged in&amp;rdquo;, the value of a setting &amp;ldquo;font size across the app&amp;rdquo;, etc. Most values are not constant, they vary over time, and we manage that in a number of ways: callbacks, delegates, &lt;code&gt;KVO&lt;/code&gt;, &lt;code&gt;NSNotificationCenter&lt;/code&gt;&amp;hellip;.&lt;/p&gt;
&lt;p&gt;Why is something like signals, which clearly represent a &lt;em&gt;real thing&lt;/em&gt; and not some crazy mathematical model, not present in our language / frameworks / design patterns? Because the inherent C-way-of-doing-things rules the way we write code. Apart from the Object Orientation abstractions, the imperative code that we write isn&amp;rsquo;t very far from Assembly: we feed instructions to the machine, and it executes them one by one, sequentially, we have to manage the data that it reads / writes in memory (state)&amp;hellip;&lt;/p&gt;
&lt;p&gt;When we write imperative code, we tell the machine &lt;strong&gt;how&lt;/strong&gt; to do the work, instead of &lt;strong&gt;what&lt;/strong&gt; work to do. This is what a new paradigm tries to accomplish: to drive us away from this low-level universe into a place closer to the way we reason and express our intentions when writing code.&lt;/p&gt;
&lt;p&gt;Now think about something for a second. Say you call a method that returns some data, let&amp;rsquo;s say a list of tweets. It doesn&amp;rsquo;t return the &lt;em&gt;present&lt;/em&gt; value, by the time the method returns, that&amp;rsquo;s already the &lt;em&gt;past&lt;/em&gt;. Just like the way our eyes don&amp;rsquo;t observe the present but some not-very-distant past.&lt;/p&gt;
&lt;p&gt;But this is not a problem, you may think, whenever the list of tweets changes, we&amp;rsquo;ll call the method again to feed the new list to our table view. I know! I&amp;rsquo;ll use a delegate! Right? Right&amp;hellip;? But what if we had an entity, a &lt;em&gt;thing&lt;/em&gt; that represented exactly that: a flow of values that change over time.&lt;/p&gt;
&lt;p&gt;So let me introduce &lt;strong&gt;two&lt;/strong&gt; constructs that I hope will make you want to use ReactiveCocoa even if just for that.&lt;/p&gt;
&lt;h3&gt;&lt;a class="anchor" href="https://gist.github.com/indragiek/9105830/a39f9de510f422737226f30f568fee5fa015b24f#bindings" id="bindings" name="bindings" rel="noreferrer"&gt;&lt;/a&gt;Bindings&lt;/h3&gt;
&lt;p&gt;Let&amp;rsquo;s say we want a signal that will carry the values of this list of tweets. Assuming that we have a &amp;ldquo;Tweet Data Provider&amp;rdquo; class with a property like this:&lt;/p&gt;
&lt;div class="highlight highlight-objc"&gt;
&lt;pre&gt;@property (nonatomic, readonly, strong) NSArray *tweets;
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;That is set whenever some other component queries the Twitter API and therefore sends KVO notifications. ReactiveCocoa makes it incredibly easy to get a signal that will send values (in this case, &lt;code&gt;NSArray&lt;/code&gt;s) every time the propery changes:&lt;/p&gt;
&lt;div class="highlight highlight-objc"&gt;
&lt;pre&gt;RACObserve(self.tweetDataProvider, tweets);
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Note the awesomeness of ReactiveCocoa handling the KVO subscription for us and removing it as soon as either &lt;code&gt;self&lt;/code&gt;, let&amp;rsquo;s say whatever ViewController we&amp;rsquo;re doing this in, or the observed object is going to be deallocated.&lt;/p&gt;
&lt;p&gt;So what we can do with this signal? We can &lt;strong&gt;bind&lt;/strong&gt; its values to something else. Look over the code of the last 5 view controllers you worked on and ping me on Twitter if you don&amp;rsquo;t think that 90% of the code there is glue-code to change some value whenever other value changes through some callback mechanism. The problem with this code is that it tends to be kind of spaghetti-y: there&amp;rsquo;s the observations in one place, the values coming in in another, and then the processing of the values somewhere else. We&amp;rsquo;re used to code like this, but we can&amp;rsquo;t deny its complexity.&lt;/p&gt;
&lt;p&gt;Again: we focus on &lt;strong&gt;how&lt;/strong&gt; the task has to be accomplished and not the &lt;strong&gt;what&lt;/strong&gt; we&amp;rsquo;re trying to do. And then there&amp;rsquo;s all the underlying trickiness that is not obvious at first, and is a common source of bugs. Is this happening in the right order? This forces us to use the debugger to analyze the state of the view controller, see what method gets called first, etc. Gross.&lt;/p&gt;
&lt;p&gt;So let&amp;rsquo;s go back to our example. How do we bind our ever-changing list of tweets to something else? With a one liner.&lt;/p&gt;
&lt;div class="highlight highlight-objc"&gt;
&lt;pre&gt;RAC(self.tableDataSource, tweets) = RACObserve(self.tweetDataProvider, tweets);
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;(&lt;em&gt;When I started using ReactiveCocoa it helped me a lot to read the &lt;code&gt;RAC()&lt;/code&gt; macro as &amp;ldquo;&lt;code&gt;RACBind&lt;/code&gt;&amp;rdquo;. So you could read this line as &amp;ldquo;Bind the tweets coming from the data provider into the table view.&amp;rdquo;&lt;/em&gt;)&lt;/p&gt;
&lt;p&gt;And before you start thinking &amp;ldquo;ah, magical code that abuses pre-processor macros&amp;rdquo;, think about what we have achieved. I don&amp;rsquo;t have to jump back and forth between 3 methods to understand what the flow of data is. This line is so descriptive that one can read it and forget about the implementation details and focus on the &lt;strong&gt;what&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;You can forget about whether the stringly-typed keypath is correct or has a typo, whether you&amp;rsquo;re implementing KVO right or your breaking your parent class, you can forget about forgetting to unsubscribe, unsubscribing without having subscribed, and a long etc. And you can simply wonder &amp;ldquo;did I tell my code to do what I want it to do?&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;Honestly, since I started using ReactiveCocoa I sleep better at night.&lt;/p&gt;
&lt;p&gt;And because you may say that this is a dumb example, I&amp;rsquo;m going to show one last example. And if you think that we don&amp;rsquo;t need to use KVO for that and we could&amp;rsquo;ve used a protocol, think about the fact that we get being KVO-complaint for free in almost all cases and creating a protocol requires a lot of boiler-plate code.&lt;/p&gt;
&lt;p&gt;So say we want to show or hide a label that says &amp;ldquo;no tweets&amp;rdquo; depending on whether there are any tweets or not. I&amp;rsquo;m sure you&amp;rsquo;re drawing the graph of method calls in your head to accomplish this. Or maybe you&amp;rsquo;re imagining the growing &lt;code&gt;-observeValueForKeyPath:ofObject:change:context:&lt;/code&gt;. Check out this descriptive code:&lt;/p&gt;
&lt;div class="highlight highlight-objc"&gt;
&lt;pre&gt;RAC(self.noTweetsLabel, hidden) = [RACObserve(self.tweetDataProvider, tweets) map:^NSNumber *(NSArray *tweets) {
    return @(tweets.count &amp;gt; 0);
}];
&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;When you call &lt;code&gt;-map:&lt;/code&gt; on a signal, it returns another signal that gets a value every time the original signal gets a value, but &amp;ldquo;maps&amp;rdquo; them to another value. In this case we&amp;rsquo;re converting &lt;code&gt;NSArray&lt;/code&gt; values into boolean (&lt;em&gt;isHidden&lt;/em&gt;?) values.&lt;/p&gt;
&lt;p&gt;If I have convinced you to at least give ReactiveCocoa a try, I would be very satisfied. But maybe you simply have to trust me when I tell you that you need to try it out for yourself to realize how incredibly useful it is.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comments&lt;/strong&gt;? Post them on the gist: &lt;a href="https://gist.github.com/JaviSoto/9098262" target="_blank"&gt;https://gist.github.com/JaviSoto/9098262&lt;/a&gt;&lt;/p&gt;</description><link>https://javisoto.tumblr.com/post/77190645097</link><guid>https://javisoto.tumblr.com/post/77190645097</guid><pubDate>Wed, 19 Feb 2014 10:26:00 -0800</pubDate><category>code reactivecocoa</category></item><item><title>Steve Jobs: Secrets of Life</title><description>&lt;p&gt;&lt;iframe frameborder="0" height="360" src="//www.youtube.com/embed/kYfNvmF0Bqw" width="640"&gt;&lt;/iframe&gt;&lt;/p&gt;</description><link>https://javisoto.tumblr.com/post/63687736388</link><guid>https://javisoto.tumblr.com/post/63687736388</guid><pubDate>Thu, 10 Oct 2013 17:19:00 -0700</pubDate></item><item><title>One year in the U.S.</title><description>&lt;p&gt;I felt like I had to write some words about this huge milestone in my life. I could try to summarize this year in one post, but that would be impossible. There&amp;rsquo;s no doubt &lt;strong&gt;these past 12 months have been the most eventful, the most different and the most fun.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;On the Christmas of 2011 I thought my new year resolution for 2012 should be something big, I should aim very high. I decided that 2012 should be the year I moved to the US to continue my professional career there. On January 30th, just 30 days in the year, I got an offer from &lt;a href="http://www.mindsnacks.com" target="_blank"&gt;MindSnacks&lt;/a&gt; to come work in San Francisco as an iOS Developer. I accepted with no hesitation, and little did I know what was ahead. And just like that &lt;strong&gt;I fulfilled an all-time dream.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Of course these things don&amp;rsquo;t come without effort and hard work. Not only to get here, but being here has been really demanding. The constant feeling of a need to get better at what you do, the pressure to build cool things. All that requires focus and perseverance. But when I look back and see how far I&amp;rsquo;ve come, I realize how worthwhile it was.&lt;/p&gt;
&lt;p&gt;I&amp;rsquo;m very thankful for how much I&amp;rsquo;ve learned here, both personally and professionally. I&amp;rsquo;m thankful for all the cool people I&amp;rsquo;ve met and I get to hang out with and who make me feel at home in San Francisco: my Spanish friends, &lt;a href="https://twitter.com/deepbane" target="_blank"&gt;Vanessa&lt;/a&gt;, &lt;a href="https://twitter.com/plunchete" target="_blank"&gt;Ignacio&lt;/a&gt; and &lt;a href="https://twitter.com/jlbelmonte" target="_blank"&gt;Juan&lt;/a&gt;, &lt;a href="http://www.mindsnacks.com/about" target="_blank"&gt;my coworkers at MindSnacks&lt;/a&gt;, my brother &lt;a href="http://www.twitter.com/nachosoto" target="_blank"&gt;Nacho&lt;/a&gt;, some nerds like &lt;a href="https://twitter.com/jordanekay" target="_blank"&gt;Jordan&lt;/a&gt; (big contributor to my still improving American accent) and &lt;a href="https://twitter.com/Sommer" target="_blank"&gt;Sommer&lt;/a&gt;, Kerrie… and other people I&amp;rsquo;m forgetting. &lt;em&gt;This goes to you all.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;</description><link>https://javisoto.tumblr.com/post/47005446970</link><guid>https://javisoto.tumblr.com/post/47005446970</guid><pubDate>Tue, 02 Apr 2013 23:05:00 -0700</pubDate><category>life</category></item><item><title>Yerba Buena Center (Taken with Instagram at Yerba Buena Center...</title><description>&lt;img src="https://64.media.tumblr.com/tumblr_ma8ws7iHDE1r8xblto1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;Yerba Buena Center (Taken with &lt;a href="http://instagram.com"&gt;Instagram&lt;/a&gt; at Yerba Buena Center for the Arts)&lt;/p&gt;</description><link>https://javisoto.tumblr.com/post/31404263778</link><guid>https://javisoto.tumblr.com/post/31404263778</guid><pubDate>Wed, 12 Sep 2012 09:36:07 -0700</pubDate></item><item><title>Goodbye Sunset District (Taken with Instagram at The Inner...</title><description>&lt;img src="https://64.media.tumblr.com/tumblr_ma3lzdockw1r8xblto1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;Goodbye Sunset District (Taken with &lt;a href="http://instagram.com"&gt;Instagram&lt;/a&gt; at The Inner Sunset)&lt;/p&gt;</description><link>https://javisoto.tumblr.com/post/31219428154</link><guid>https://javisoto.tumblr.com/post/31219428154</guid><pubDate>Sun, 09 Sep 2012 12:54:49 -0700</pubDate></item><item><title>How I manage to get more work done</title><description>&lt;p&gt;I got out of the office today with a good feeling about my productivity. I realized how much work I had gotten done today, and thinking back, how much work I’ve been getting done lately, compared to before. I tweeted this:&lt;/p&gt;
&lt;p&gt;&lt;figure class="tmblr-full" data-orig-height="90" data-orig-width="500"&gt;&lt;img src="https://64.media.tumblr.com/f213136f220a6a213d4fdf5a81907443/8df9a7f0b97188bd-5d/s540x810/447b3d28083764b0e8f34f994644c58dac592a6f.png" data-orig-height="90" data-orig-width="500"/&gt;&lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;It was kind of a rhetoric “&lt;em&gt;should&lt;/em&gt;”, because talking about this is tricky, since a lot of it has to do with one’s personal habits, but &lt;a href="http://www.twitter.com/refulgentis" target="_blank"&gt;@refulgentis&lt;/a&gt; encouraged me to actually write that post, so here it goes.&lt;/p&gt;
&lt;p&gt;This all started when I read &lt;a href="http://psql.me/post/26232740069/turning-off-push-for-email" target="_blank"&gt;this post&lt;/a&gt; by &lt;a href="http://www.twitter.com/pasql" target="_blank"&gt;@pasql&lt;/a&gt; talking about how happy he was after turning off push for e-mail, after also having a similar discussion with &lt;a href="http://www.twitter.com/deepbane" target="_blank"&gt;@deepbane&lt;/a&gt; about it. For some reason, ever since I got my first iPhone I’ve become obsessed with getting real time notifications of everything. When I read that post, I realized that e-mail is actually not urgent. If someone sends you an e-mail, they can’t be expecting that you read it inmediately. If they want to reach you quickly, they will call or text you. Not to mention that 90% of e-mails are not even &lt;em&gt;personal e-mails&lt;/em&gt;, they’re notifications from some sort of service.&lt;/p&gt;
&lt;p&gt;So I not only turned off push, I even turned off automatically pulling e-mails from the server (I set it to “manual”). I was scared at first: “What if I get something important?”. After a few days, I realized I wasn’t missing anything. What did happen, is that my phone wasn’t vibrating in my poket every minute. And this meant fewer interruptions: both at work, and in my free time. This was the first great decision, which has improved my productivity, and my &lt;em&gt;peace of mind&lt;/em&gt; significantly. I encourage you to do the same today.&lt;/p&gt;
&lt;p&gt;The reason for this is that we, humans, aren’t good at multi-tasking. We can do multiple things at the same time, but we can’t do them right, we can’t focus on all of them with the necessary level of attention: &lt;strong&gt;if we want to do something right, we must focus only on that task.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The second improvement came thanks to a small feature added to iOS6, which I installed around a month ago, called &lt;strong&gt;Do Not Disturb.&lt;/strong&gt; I estimate I receive around 2 to 3 push notifications per minute on my phone during peak hours. That’s A LOT of interruptions: Twitter, Facebook, Instagram, Path, Foursquare just to mention some examples. Just like with e-mail: are those notifications urgent? Do you really have to check them out as soon as you receive them? The answer is no, but we live so addicted to our smartphone (some of us anyway) that we forget this. What this feature does basically, is that even though the phone will still receive all those notifications, it just won’t light up the screen or vibrate, unless it’s a phone call (which is normally more urgent, and it’s definitely not as frequent), so it won’t interrupt you. Whenever you want, you can press the home button, and see all you’ve received since the last time you checked. The key is that &lt;strong&gt;you choose when you want to look&lt;/strong&gt;. In the mean time, you’re focused on your task, in my case, programming.&lt;/p&gt;
&lt;p&gt;As you can see, it all comes down to one thing: not being interrupted. It’s amazing how easy it becomes to &lt;em&gt;be in the zone &lt;/em&gt;after &lt;strong&gt;being focused for around 20-30 minutes without a single interruption&lt;/strong&gt;. It’s in that state that I manage to get the most work done, and with the highest quality.&lt;/p&gt;
&lt;p&gt;I could get into the details of what tools I use to check my mail, manage my todo’s and so on, but that would be material for a whole new post.&lt;/p&gt;
&lt;p&gt;And you, what do you do to keep up your productivity?&lt;/p&gt;</description><link>https://javisoto.tumblr.com/post/28036903364</link><guid>https://javisoto.tumblr.com/post/28036903364</guid><pubDate>Thu, 26 Jul 2012 09:56:32 -0700</pubDate></item><item><title>I wanted to share this cool picture that Jarod took of me...</title><description>&lt;img src="https://64.media.tumblr.com/tumblr_m6xhbnhFSK1r8xblto1_r1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;I wanted to share this cool picture that &lt;a href="https://twitter.com/jarodl/" title="Jarod" target="_blank"&gt;Jarod&lt;/a&gt; took of me (right) and my brother &lt;a href="https://twitter.com/nachosoto/" title="Nacho" target="_blank"&gt;Nacho&lt;/a&gt; (left) at the office.&lt;/p&gt;
&lt;p&gt;So what were we doing? We were working. Writing on a glass. Yep. We were discussing how to implement a piece of functionality for the &lt;a href="http://www.mindsnacks.com" title="MindSnacks" target="_blank"&gt;MindSnacks&lt;/a&gt; app, before actually coding it.&lt;/p&gt;</description><link>https://javisoto.tumblr.com/post/26892152194</link><guid>https://javisoto.tumblr.com/post/26892152194</guid><pubDate>Mon, 09 Jul 2012 23:49:00 -0700</pubDate></item><item><title>Starting from scratch: welcome to my blog (again)</title><description>&lt;p&gt;This blog has existed for months, but I never wrote on it, but still I had over one thousand posts. &lt;em&gt;How is that even possible&lt;/em&gt;? Well, I was just using &lt;a href="http://www.ifttt.com" title="ifttt" target="_blank"&gt;iftt&lt;/a&gt; hooks to fill this with the same stuff that I was already sharing on Twitter anyway. So along with a new website (&lt;a href="http://www.javisoto.es" title="javisoto.es" target="_blank"&gt;http://www.javisoto.es&lt;/a&gt;) I decided to actually have a blog here and write from time to time :)&lt;/p&gt;</description><link>https://javisoto.tumblr.com/post/25249323329</link><guid>https://javisoto.tumblr.com/post/25249323329</guid><pubDate>Sat, 16 Jun 2012 14:45:00 -0700</pubDate></item></channel></rss>
