Skip to content

Instantly share code, notes, and snippets.

View RuiAAPeres's full-sized avatar
💭
🏔🏃‍♂️

Rui Peres RuiAAPeres

💭
🏔🏃‍♂️
View GitHub Profile
//
// Signal+Extensions.swift
// Khan Academy
//
// Created by Nacho Soto on 10/1/15.
// Copyright © 2015 Khan Academy. All rights reserved.
//
import ReactiveCocoa
@JadenGeller
JadenGeller / List Comprehension.swift
Last active March 17, 2018 03:45
Nondeterministic Computation with Arrays
// 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 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 }
}
@kongtomorrow
kongtomorrow / gist:e153a95907d188fb078a
Created June 10, 2014 22:52
@auto_closure for control over evaluation
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)!")