Skip to content

Instantly share code, notes, and snippets.

@naoty
naoty / Parser.swift
Last active August 29, 2015 14:23
Simple parser combinator in Swift
typealias Parser = String -> (String, String)
func charParser(char: Character) -> Parser {
return { text in
if text[text.startIndex] == char {
return (String(char), text[advance(text.startIndex, 1)..<text.endIndex])
}
return ("", text)
}
}
@naoty
naoty / Functor.swift
Last active September 26, 2015 17:52
import Foundation
struct Box<T> {}
protocol Functor {
typealias A
typealias B
typealias Boxed = Box<B>
func fmap<B>(f: A -> B) -> Boxed
import Foundation
enum MaybeInt {
case Nothing
case Just(Int)
}
extension MaybeInt : Printable {
var description : String {
switch self {
AllCops:
RunRailsCops: true
Exclude:
- ",/**/*"
- ".git/**/*"
- "bin/*"
- "db/schema.rb"
- "db/migrate/*.rb"
- "log/**/*"
- "public/**/*"
@naoty
naoty / blog.css
Last active August 29, 2015 14:16
/* <system section="theme" selected="evergreen"> */
@import "/css/theme/evergreen/evergreen.css";
/* </system> */
#container {
width: 800px;
}
#container-inner {
margin-top: 60px;
/* See Kobito.app/Contents/Resources/markdown.css for predefined style. */
/* ------------------------------
* HTML element
* ------------------------------ */
html {
background-color: #FFFFFF;
padding: 0;
}
var originalHref = document.querySelector(".articles-show-click").href;
if (originalHref != null) {
location.href = originalHref;
}
mport Foundation
let components = NSURLComponents()
components.scheme = "http"
components.host = "example.com"
components.path = "/hoge"
components.query = "q=keyword"
println(components.URL) //=> "http://example.com/hoge?q=keyword"
class Stream<T> {
var subscribers: [(T) -> Void] = []
func subscribe(subscriber: (T) -> Void) {
subscribers.append(subscriber)
}
func publish(message: T) {
for subscriber in subscribers {
subscriber(message)