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
fun doSomething(path: String) { | |
val content: String //instead of declare as `var content: String? = null` | |
val br = BufferedReader(FileReader(path)) | |
var currentLine = br.readLine() | |
content = buildString { | |
while (currentLine != null) { | |
appendln(currentLine) | |
currentLine = br.readLine() |
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 Parent { | |
let id: Int | |
let children: [Int] | |
} | |
struct Node { | |
let id: Int | |
let parent: Int | |
let children: [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
struct Error : ErrorType { | |
let message: String | |
} | |
struct Json { | |
let dictionary: [String : AnyObject] | |
init?(dictionary: [String : AnyObject]?) { | |
guard let dictionary = dictionary else { return 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
interface Fooable { | |
fun foo(): String | |
} | |
class FooImpl : Fooable { | |
override fun foo() = "I am fooImpl" | |
} | |
class AnotherFooImpl : Fooable { | |
override fun foo() = "I am anotherFooImpl" |
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
//a somewhat contrived example of how reactive programming can be useful | |
//some real concerns that are omitted, but can be easily accomplished using rxswift are | |
//error handling, displaying loading indicators, etc | |
// A result object that comes from the network. | |
// The contents are irrelevant for this example. | |
struct Result { | |
let text: String | |
let someOtherThing: 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
std::unordered_map<std::string,std::string> m{{"1", "2"}, {"3", "4"}, {"5", "6"}}; | |
std::unordered_map<std::string,std::string> ms; | |
std::transform(std::begin(m), std::end(m), std::inserter(ms, std::begin(ms)), [](const auto& p) { return {p.first, p.first}; }; |
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 UIKit | |
/*: | |
## Redux | |
A Predictable state container for not just JavaScript apps | |
*/ | |
/*: | |
### Action | |
Payload of information from app to your __Store__ |
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
// | |
// UIScrollView+RACSupport.h | |
// Taskworld | |
// | |
// Created by Kittinun Vantasin on 8/5/15. | |
// Copyright (c) 2015 Taskworld. All rights reserved. | |
// | |
@import UIKit; |
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 User(val id: Int, val name: String, val age: Int, val email: String) { | |
class Deserializer : Deserializable<User> { | |
override val deserializer: (JSON) -> Result<User, Exception> = { json -> | |
::User.create. | |
map(json at "id"). | |
apply(json at "name"). | |
apply(json at "age"). | |
apply(json at "email") | |
} |
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
- (RACSignal *)rac_requestWithMethod:(NSString *)method path:(NSString *)path parameters:(id)parameters { | |
return [[RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) { | |
NSError *error; | |
NSURLRequest *request = [self.requestSerializer requestWithMethod:method URLString:[[NSURL URLWithString:path relativeToURL:self.baseURL] absoluteString] parameters:parameters error:&error]; | |
if (error) { | |
[subscriber sendError:error]; | |
return nil; | |
} |