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 Foundation | |
extension Sequence { | |
func filterNot(_ isExcluded: (Self.Iterator.Element) throws -> Bool) rethrows -> [Self.Iterator.Element] { | |
var res: [Self.Iterator.Element] = [] | |
for e in self where try !isExcluded(e) { | |
res.append(e) | |
} | |
return res |
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 Foundation | |
import MessagePack | |
// used https://github.com/a2/MessagePack.swift | |
// MARK: - PackableI/F | |
protocol Packable { | |
func toPackValue() -> MessagePackValue | |
init?(packValue: MessagePackValue) |
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 Foundation | |
/// See also | |
// http://qiita.com/tsuruchika/items/9ca9c4811e1f28b9417c | |
// http://qiita.com/moaible/items/85d80173bb8ed7f64b74 | |
// http://fromatom.hatenablog.com/entry/2015/07/15/192328 | |
public struct Regex { | |
private let pattern: String |
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
class Semver { | |
constructor(major, minner, patch) { | |
this.major = major; | |
this.minner = minner; | |
this.patch = patch; | |
} | |
toString() { | |
return `${this.major}_${this.minner}_${this.patch}`; | |
} |
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
typealias ExecuteOnce = () -> Void | |
func executeOnce(f: () -> Void) -> ExecuteOnce { | |
var first = true | |
return { | |
if first { | |
first = false | |
f() | |
} | |
} |
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 Foundation | |
extension Array { | |
var empty: Bool { | |
return count == 0 | |
} | |
var nonEmpty: Bool { | |
return !empty | |
} |
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 Foundation | |
final class InMemoryUserDefaults: NSUserDefaults { | |
static let SuiteName = "InMemory" | |
private var data: [String: AnyObject?] | |
override init?(suiteName suitename: String?) { | |
data = [:] |
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 Foundation | |
/// See also | |
/// - https://github.com/kasei/SwiftRegex | |
struct Regex { | |
private let pattern: String | |
private let internalRegexp: NSRegularExpression | |
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
object Euler { | |
// http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%205 | |
def main(args: Array[String]) { | |
// val r1 = test(10) | |
val r = (1L to 20L).reduceLeft(lcm) | |
println(r) | |
} | |
// def test(n: Int) = (20 to Int.MaxValue).find(x => (2 to n).forall(x % _ == 0)) |
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
/** | |
* 代数的データ型 | |
*/ | |
object AlgebraicDataTypes extends App { | |
import Bool._ | |
println(True.id) // 0 | |
println(Bool(0)) // True | |
println(Bool.withName("True")) // True |