I hereby claim:
- I am zlangley on github.
- I am zlangley (https://keybase.io/zlangley) on keybase.
- I have a public key whose fingerprint is 5D32 FC6E 8D11 DBB9 BC02 60FC BC01 F550 E214 9E3E
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
| import Dispatch | |
| import PromiseKit | |
| /// A wrapper for a function that creates a Promise. | |
| public class PromiseOperation<T> { | |
| private let makePromise: () -> Promise<T> | |
| public init(makePromise: @escaping () -> Promise<T>) { | |
| self.makePromise = makePromise | |
| } |
| // | |
| // OrderedSet.swift | |
| // OrderedSet | |
| // | |
| // Created by Zach Langley on 11/17/15. | |
| // Copyright © 2015 Zach Langley. All rights reserved. | |
| // | |
| public struct OrderedSet<Element: Hashable>: ArrayLiteralConvertible, RangeReplaceableCollectionType { | |
| private var indexForElement: Dictionary<Element, Int> = [:] |
| # Assumes all header/implementation files want the filename on the second line. | |
| # Run from your src directory. | |
| for f in `find . -name '*.[mh]'`; do sed -i "" "2 s|.*|// `basename $f`|" "$f"; done |
| def memoize[T, U](f: T => U) = { | |
| val cache = scala.collection.mutable.HashMap[T, U]() | |
| (t: T) => { | |
| if (!cache.contains(t)) { | |
| cache.put(t, f(t)) | |
| } | |
| cache.get(t).get | |
| } | |
| } |
| func memoize<T: Hashable, U>(f: ((T -> U), T) -> U) -> (T -> U) { | |
| var cache = [T: U]() | |
| var memoized: (T -> U)! | |
| memoized = { n in | |
| if cache[n] == nil { | |
| cache[n] = f(memoized, n) | |
| } | |
| return cache[n]! | |
| } | |
| return memoized |