def curry[A, B, C, D](f: (A, B, C) => D): A => B => C => D = ???
def uncurry[A, B, C, D](f: A => B => C => D): (A, B, C) => D = ???
def compose[A, B, C, D](f: A => B, g: B => C, h: C => D): A => D = ???
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
-- 二分木が平衡状態であるという事を,各節点で 3(m + 1) ≧ n + 1 かつ 3(n + 1) ≧ m + 1 が成り立つ事とします。(n,mは左右の部分木の節点数) | |
-- 二分木が平衡状態か否かを判定する関数を相互再帰定理に基いて導出して下さい。 | |
-- https://gist.github.com/eldesh/5970931 | |
data Tree a = Leaf a | Node (Tree a) a (Tree a) deriving(Show, Eq) | |
instance Foldable Tree where | |
foldr f z (Leaf x) = f x z | |
foldr f z (Node l k r) = foldr f (f k (foldr f z r)) l | |
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
data BTree a = BLeaf | BNode (BTree a) (BTree a) | |
count :: BTree a -> Integer | |
count BLeaf = 1 | |
count (BNode l r) = count l + count r | |
foldTree f z BLeaf = z | |
foldTree f z (BNode l r) = f (foldTree f z l) (foldTree f z r) |
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
let disposeBag = DisposeBag() | |
let scheduler = OperationQueueScheduler(operationQueue: NSOperationQueue()) | |
[1,2,3,4,5].asObservable() | |
.observeOn(scheduler) | |
.subscribeNext({ (num) -> Void in | |
NSLog("background: \(num)") | |
}) | |
.addDisposableTo(disposeBag) | |
NSLog("main") |
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
let disposeBag = DisposeBag() | |
let scheduler = SerialDispatchQueueScheduler(globalConcurrentQueuePriority: .Default) | |
[1,2,3,4,5].asObservable() | |
.observeOn(scheduler) | |
.subscribeNext({ (num) -> Void in | |
NSLog("background: \(num)") | |
}) | |
.addDisposableTo(disposeBag) | |
NSLog("main") |
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
interface ImmediateSchedulerType | |
interface SchedulerType | |
ImmediateSchedulerType <|- SchedulerType | |
SchedulerType <|- SerialDispatchQueueScheduler | |
SerialDispatchQueueScheduler <|- MainScheduler | |
interface ImmediateSchedulerType { | |
+ schedule<StateType> |
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
button.rx_tap | |
.flatMap { () -> Observable<String> in | |
if (self.textField3.text?.characters.count > 0) ?? false { | |
return just(String(self.textField3.text!)) | |
} else { | |
return failWith(NSError(domain: "app error", code: -1, userInfo: nil)) | |
} | |
} | |
.subscribe( | |
onNext: { self.showAlert("値は\($0)") }, |
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
public protocol Service { | |
func addPrefix(name: String) -> String | |
} | |
public class MsService: Service { | |
public func addPrefix(name: String) -> String { return "Ms." + name } | |
} | |
public class MrService: Service { | |
public func addPrefix(name: String) -> String { return "Mr." + name } |
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 C { func appendC(s: String) -> String } | |
class CImpl: C { | |
private let b: B | |
init(b: B) { self.b = b } //⚡️ CImpl は B のインスタンスを要求する | |
func appendC(s: String) -> String { return b.appendB(s) + "c" } | |
} | |
protocol B { func appendB(s: String) -> String } | |
class BImpl: B { | |
private let a: 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
typealias ContextType = protocol<AComponent, ABComponent> | |
class Context { | |
private let type: ContextType.Type | |
init(type: ContextType.Type) { self.type = type } | |
var a: A { return type.a } | |
var ab: AB { return type.ab } | |
} | |
class DebugContext: DefaultAComponent, DefaultABComponent { | |
static let a: A = DebugContext.createA() | |
static let ab: AB = DebugContext.createAB() |