This file contains hidden or 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
protocol ClientType: Hashable { | |
var fullName: String { get } | |
} | |
extension ClientType { | |
var hashValue: Int { | |
return fullName.hashValue | |
} | |
} |
This file contains hidden or 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
/*: | |
Brandon Williams | |
# Lenses in Swift | |
*/ | |
/*: | |
## i.e. Functional getters and setters |
This file contains hidden or 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
//: Playground - noun: a place where people can play | |
import Cocoa | |
import Foundation | |
// WinterBuddies a social network to connect you with people who can help you survive the winter | |
class ProfileViewController : UIViewController { | |
let musicService = MusicService() |
This file contains hidden or 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 hidden or 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
First step is to desugar do notation. In this case we want to translate it to the bind (>>=) operator: | |
greeter = | |
name >>= ask | |
return ("hello, " ++ name ++ "!") | |
Now that it's desugared (not convinced I've done it correctly) I will translate it to Swift. | |
I'm relying on the Reader monad implementation in Swiftz (https://github.com/typelift/Swiftz/blob/968075391aedb15ec51ff9d5b7d4921b8fa3a3c6/Swiftz/Reader.swift) | |
Current code is: |
This file contains hidden or 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
// Based off of https://gist.github.com/runarorama/33986541f0f1ddf4a3c7 | |
protocol λ { | |
typealias α | |
} | |
struct K<L: λ>: λ { | |
typealias α = L.α | |
} |
This file contains hidden or 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
trait λ { | |
type α | |
} | |
trait Functor extends λ { | |
type α <: λ | |
def map[A,B](x: α { type α = A })(f: A => B): α { type α = B } | |
} |
This file contains hidden or 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
import Foundation | |
class Box<T> { | |
let unbox: T | |
init(_ value: T) { self.unbox = value } | |
} | |
struct Notification<A> { | |
let name: String | |
} |
This file contains hidden or 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
import Prelude | |
public struct Lens<A, B> { | |
private let get: A -> B | |
private let set: (A, B) -> A | |
public init(get: A -> B, set: (A, B) -> A) { | |
self.get = get | |
self.set = set | |
} |
This file contains hidden or 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 is an introduction to Transducers in Swift, inspired by | |
// Talk: https://www.youtube.com/watch?v=estNbh2TF3E | |
// Code: https://github.com/mbrandonw/learn-transducers-playground | |
// Updated with Swift 2 | |
/** | |
* Define a few test methods | |
*/ | |
/// REDUCER | |
func append <A> (xs: [A], x: A) -> [A] { return xs + [x] } |
NewerOlder