This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Signal+Extensions.swift | |
// Khan Academy | |
// | |
// Created by Nacho Soto on 10/1/15. | |
// Copyright © 2015 Khan Academy. All rights reserved. | |
// | |
import ReactiveCocoa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In languages like Python and Haskell, we can write list comprehension syntax like | |
// super simply to generate complex lists. Below, for example, we find all numbers that are | |
// the product of two sides of a triangle. | |
// [a * b | a <- [1..10], b <- [1..10], c <- [1..10], a * a + b * b == c * c] | |
// Why is this called nondeterministic computation? Because we essentially try ALL possible combinations | |
// of these values (a,b) and--you can imagine--run them all simultanously and get the result that matches the predicate. | |
// Now, obviously, this doesn't all happen at the same time, but that's the idea behind the nondeterminism. | |
// Let's examine how we can get a similiar result in Swift! We'll start super simple and work |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This accompanies http://chris.eidhof.nl/posts/repmin-in-swift.html | |
import UIKit | |
// Unfortunately, we need Box | |
public class Box<T> { | |
public let unbox: T | |
public init(_ value: T) { self.unbox = value } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func myAnd(lhs : Bool, rhs : @auto_closure () -> Bool) -> Bool { | |
if lhs { | |
return rhs() | |
} else { | |
return false | |
} | |
} | |
func logAndBool(val : Bool) -> Bool { | |
println("evaluating and returning \(val)!") |
NewerOlder