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
| // A thing I want to do | |
| // This flow only involves **one** promise, for example an ajax call | |
| // None of the subsequent `then` or `catch` calls, return new promises. | |
| var explode = false; | |
| var promise = new Promise(function(resolve, reject) { | |
| if (explode) { |
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
| -- script.lua | |
| -- Receives a table, returns the sum of its components. | |
| io.write("The table the script received has:\n"); | |
| x = 0 | |
| for i = 1, #foo do | |
| print(i, foo[i]) | |
| x = x + foo[i] | |
| end | |
| io.write("Returning data back to C\n"); | |
| return x |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
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
| //@auto_closure hack to prevent `LLVM ERROR: unimplemented IRGen feature! non-fixed multi-payload enum layout` | |
| //as in https://github.com/maxpow4h/swiftz/blob/master/swiftz/Either.swift | |
| enum Either<L,R> { | |
| case Left(@auto_closure () -> L) | |
| case Right(@auto_closure () -> R) | |
| func flatMapLeft<L1>(f: (L) -> Either<L1, R>) -> Either<L1, R> { | |
| switch self { | |
| case let .Left(l): return f(l()) | |
| case let .Right(r): return .Right(r) |
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 Monad { | |
| typealias F | |
| typealias U | |
| class func bind<M : Monad where M.U == U>(Self, F -> M) -> M | |
| class func `return`(F) -> Self | |
| } | |
| extension Array : Monad { | |
| typealias F = T |
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/Foundation.h> | |
| #import <ReactiveCocoa/ReactiveCocoa.h> | |
| @interface PASDataSource : NSObject | |
| @property (nonatomic, strong, readonly) NSArray *passes; | |
| + (PASDataSource *)sharedInstance; | |
| - (RACSignal *)refreshPassInfoSignal; |
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 ISubscriber { | |
| typealias Element | |
| func disposable() -> RACCompoundDisposable | |
| func sendNext(e: Element) | |
| func sendError(e: NSError) | |
| func sendCompleted() | |
| } |
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
| // | |
| // ViewController.swift | |
| // TestSwift | |
| // | |
| // Created by Jameson Quave on 6/2/14. | |
| // Copyright (c) 2014 JQ Software LLC. All rights reserved. | |
| // | |
| import UIKit | |