Skip to content

Instantly share code, notes, and snippets.

View 53ningen's full-sized avatar
🐰
Is the Order a Rabbit?

gomi_ningen 53ningen

🐰
Is the Order a Rabbit?
View GitHub Profile

2. getting started

2.1 次を実装せよ

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 = ???
-- 二分木が平衡状態であるという事を,各節点で 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
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)
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")
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")
interface ImmediateSchedulerType
interface SchedulerType
ImmediateSchedulerType <|- SchedulerType
SchedulerType <|- SerialDispatchQueueScheduler
SerialDispatchQueueScheduler <|- MainScheduler
interface ImmediateSchedulerType {
+ schedule<StateType>
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)") },
@53ningen
53ningen / di.swift
Last active February 8, 2016 19:15
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 }
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
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()