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 something() (int,int) { | |
return 1,2 | |
} |
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 sum(lhs : Int)(rhs : Int) -> Int { | |
return lhs + rhs | |
} | |
let sum2 = sum (2) | |
let pair1 = sum2(rhs: 1) | |
let pair2 = sum2(rhs: 2) | |
let pair3 = sum2(rhs: 3) | |
let pair4 = sum2(rhs: 4) |
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
//The magic method | |
-(id (^)(id,...)) getSelector:(SEL) aSelector forTarget:(id) target withFirstArgument:(id) firstArgument { | |
id (^blockName)(id,...) = ^id(id values,...) { | |
id cenas = firstArgument; | |
SEL theSelector; | |
NSMethodSignature *aSignature; | |
NSInvocation *anInvocation; |
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 curry<T,U,V>(f:(T,U)->V) -> T -> U -> V | |
{ | |
return {x in { y in f(x,y)}} | |
} | |
extension Array { | |
var decompose : (T,[T])? { | |
return (count > 0) ? (self[0], Array(self[1..<count])) : nil | |
} | |
} |
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
public final class Box<T> | |
{ | |
let value : T | |
public init(_ value : T) { | |
self.value = value | |
} | |
} | |
func flatten<T>(box : Box<Box <T>>) -> Box <T> { |
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
import Foundation | |
import ReactiveCocoa | |
final class PriorityAction<T> { | |
let identifier : String | |
let action : Action<Void, [T], Error> | |
init(identifier: String, action: Action<Void, [T], Error>) { | |
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
protocol Foo { | |
typealias T: Hashable | |
var foos: [T] { get } | |
} | |
struct Bar<T: Equatable>: Foo { | |
let foos: [T] | |
init(foos: [T]) { |
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 fetchData(request: NSURLRequest) -> SignalProducer<[Foo], Error> { | |
return foosFromServer(request).flatMapError {_ in //network failed deal with it} | |
.flatMapLatest { parseFoos($0).flatMapError {_ in //parse failed deal with it} } | |
.flatMapLatest { persistFoos($0).flatMapError {_ in //persist failed deal with it} } | |
.flatMapError { error in loadFoosFromCache().mapError {_ in error} } | |
} |
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
1. The work should only be started when we spend more than 0.5s in the ViewController | |
2. Check if there is data in the cache | |
2.1 Success: Show it and start an internet request if the cache is outdated | |
2.1.1 Success: Show the data | |
2.1.2 Failed: Silently fail | |
2.2 Fail: Try to get data from the internet | |
2.2.1 Success: Show it | |
2.2.2 Fail: Show the error | |
3. Every 5 minutes start internet request check, if cache is outdated && ViewController is visible | |
3.1 Success: Show the data |
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
class TableDataSource: UITableViewDataSource { | |
let viewModels: [ViewModel] | |
init(viewModels: [ViewModel]) { | |
self.viewModels = viewModels | |
} | |
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { | |