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 BaseContext { | |
var cloudKitApiKey: String {get} | |
var todosDataSource: TodosDataSource {get} | |
} | |
class AppContext: BaseContext { | |
var cloudKitApiKey = "sjsfAJ&76sdgjhs3434JHS3" | |
var todosDataSource: TodosDataSource = TodosCloudKitDataSource() | |
} | |
class TodosListContext: AppContext { |
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 CounterViewController: UIViewController { | |
@IBOutlet weak var label: UILabel? | |
@IBOutlet weak var minus: UIButton? | |
@IBOutlet weak var plus: UIButton? | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
typealias State = Int |
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
enum Event { | |
case addTodo(Todo) | |
case toggleTodo(Todo) | |
case setVisibilityFilter(VisibilityFilter) | |
case storeTodos() | |
case todosStored(Bool) | |
} | |
struct State { | |
var todos: [Todo] |
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 loginWithFacebook() -> AsyncResult<Context, String, GenericError> { | |
return AsyncResult.unfoldTT{ context, continuation in | |
let loginManager = LoginManager() | |
loginManager.logIn([ .publicProfile ], viewController: self) { loginResult in | |
switch loginResult { | |
case .Failed(let error): | |
continuation(Result.failure(error)) | |
case .Cancelled: | |
continuation(Result.failure(LoginCancelledError())) | |
case .Success(let grantedPermissions, let declinedPermissions, let accessToken): |
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 reduce(state: State, event: Event) -> State { | |
switch event { | |
case .addTodo(let todo): | |
var newState = state | |
newState.todos = state.todos + [todo] | |
return newState | |
case .toggleTodo(let todo): | |
var newState = state | |
newState.todos = state.todos.map { t in | |
var newTodo = 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
enum Event { | |
case addTodo(Todo) | |
case toggleTodo(Todo) | |
case setVisibilityFilter(VisibilityFilter) | |
} |
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
struct Todo { | |
var text: String | |
var completed: Bool | |
} | |
enum VisibilityFilter { | |
case showCompleted | |
case showAll | |
} | |
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 Monads | |
func test() { | |
typealias DeferredResult<T> = Deferred<Result<T, String>> | |
typealias AsyncResult<T> = Effect<DeferredResult<T>> | |
struct User { | |
var name: String | |
var dateOfBirth: String | |
} |
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
'use strict'; | |
const R = require('ramda'); | |
const S = require('sanctuary'); | |
const data = { | |
id: 1, | |
orderName: 'Order from spain', | |
teamName: 'Portland penguins', |
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
//You can react to the validation result value, either it's a success or a failure | |
let success: Validation<String, Int> = Validation.Success(1) | |
switch(success){ | |
case .Success(let value): | |
print(value) | |
case .Failure(let error): | |
print(error) | |
} | |
// ==> Print(1) |
NewerOlder