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
#!/bin/sh | |
wget http://www.morinaga.co.jp/cocoa/milk/message.ogg | |
wget http://nbcuni-audio.edgesuite.net/20161107.mp3 |
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
indirect enum TailRec<T> { | |
case Done(T) | |
case More(() -> TailRec<T>) | |
func run() -> T { | |
var tailRec = self | |
while true { | |
switch tailRec { | |
case .More(let next): tailRec = next() | |
case .Done(let t): return 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
/// `* -> *` | |
public class K1<A> { public init() {} } | |
public protocol Functor { | |
associatedtype A | |
associatedtype B | |
associatedtype FB = K1<B> | |
func fmap(f : A -> B) -> FB | |
} |
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
; your code goes here | |
(define (square x) (* x x)) | |
(define (sum-of-square x y) (+ (square x) (square y))) | |
(define (q13 x y z) (cond | |
((and (>= y x) (>= z x)) (sum-of-square y z)) | |
((and (>= x y) (>= z y)) (sum-of-square x z)) | |
(else (sum-of-square x y)) | |
)) |
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
### nil check for boolean | |
``` | |
% cat ./NilCheckForBoolean.swift | |
import Foundation | |
func target() { | |
for _ in 1...100000 { | |
let e: Bool? = true | |
if e == 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
import Swift | |
import Foundation | |
let observable = BehaviorSubject(value: "cocoa") | |
let observer = AnyObserver<String> { | |
switch $0 { | |
case .Next(let str): NSLog(str) | |
default: break | |
} | |
} |
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 Hoge { | |
case Next | |
case Error | |
} | |
func piyo(arg: Hoge?) -> Bool { | |
return arg != nil | |
} | |
func foo(arg: Bool) -> Bool { |
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
; ModuleID = 'Hoge' | |
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" | |
target triple = "x86_64-apple-macosx10.9" | |
%Vs5Int32 = type <{ i32 }> | |
%Sp = type <{ i8* }> | |
%swift.type = type { i64 } | |
%swift.type_pattern = type opaque | |
%swift.protocol_conformance = type { i32, i32, i32, i32 } | |
%swift.protocol = type { i8*, i8*, i8*, i8*, i8*, i8*, i8*, i8*, i32, i32 } |