% find . -name "*.storyboard" | xargs sed -i "" '-e s/colorSpace="calibratedRGB"/colorSpace="custom" customColorSpace="sRGB"/g'
% find . -name "*.xib" | xargs sed -i "" '-e s/colorSpace="calibratedRGB"/colorSpace="custom" customColorSpace="sRGB"/g'
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
// see: http://comonad.com/reader/2008/rotten-bananas/ | |
trait InvariantFunctor[F[_]] { | |
def xmap[A, B](fa: F[A])(f: A => B, g: B => A): F[B] | |
} | |
implicit val optionalInvariantFunctor = new InvariantFunctor[Option] { | |
def xmap[A, B](fa: Option[A])(f: A => B, g: B => A): Option[B] = fa match { | |
case Some(a) => Some(f(a)) | |
case _ => None | |
} |
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 scala.language.higherKinds | |
trait Functor[F[+_]] { | |
def map[A, B](a: F[A])(f: A => B): F[B] | |
} | |
implicit val optionalFunctor = new Functor[Option] { | |
def map[A, B](a: Option[A])(f: A => B): Option[B] = a.map(f) | |
} |
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
func const<A, B>(_ a: A) -> (B) -> A { | |
return { _ in a } | |
} | |
struct LazyRecoverable<A> { | |
private let original: A | |
private var updatef: ((A) -> A)? | |
private var mutableCopy: A | |
init(_ original: A) { |
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
extension UTF8 { | |
static func byteCount(_ input: UnicodeScalar) -> Int { | |
var count = 0 | |
encode(input, into: { _ in count = count + 1 }) | |
return count | |
} | |
static func is4Bytes(_ input: UnicodeScalar) -> Bool { | |
return byteCount(input) == 4 | |
} |
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
struct KeyPath { | |
let key: String | |
init(_ key: String) { | |
self.key = key | |
} | |
} | |
extension KeyPath: ExpressibleByStringLiteral { |
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
class Lazy<A> { | |
private let a: () -> A | |
private lazy var lazyA: A = { | |
return self.a() | |
}() | |
var value: A { | |
return lazyA | |
} |
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
typealias MyTuple = (hoge: Int, hoge: String) // 同じ名前のラベルが置ける | |
let myTuple = MyTuple(hoge: 1, hoge: "Hello") | |
print(myTuple.hoge) // 1 | |
func stringFunc(text: String) { } | |
// NG: 型推論はできない | |
// stringFunc(text: myTuple.hoge) |
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 LoginState { } | |
final class Login: LoginState { } | |
final class Logout: LoginState { } | |
class LoginStateAction<State>: LoginStateActionType { } | |
protocol LoginStateActionType { | |
func loginState() -> LoginStateAction<Login>? | |
func logoutState() -> LoginStateAction<Logout>? | |
} |
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 Creature { } | |
protocol Animal: Creature { } | |
struct Dog: Animal { } | |
struct Cat: Animal { } | |
// OK | |
class Hoge<A> { } | |
let hoge = Hoge<Animal>() // OK |