requestSharedWebCredential(#domain: String, completion: (credential public class func requestSharedWebCredential(#domain: String, account: String, comple private class func requestSharedWebCredential(#domain: String?, account: String?, com
Swadling on 3/06/2014. // Copyright (c) 2014 Maxwell Swadling. All rights reserved. // import class Foundation.NSError /// The Either type represents values with two possibilities: a value of type Either <A, B> is either /// Left <A> or Right <B>. /// /// The Either type is sometimes used to represent a value which is either correct or an error; by /// convention, the Left constructor is used to hold an error value and the Right constructor is /// used to hold a correct value (mnemonic: "right" also means "correct"). public enum Either<L, R> { case Left(Box<L>) case Right(Box<R>) /// Converts a Either to a Result, which is a more specialized type that /// contains an NSError or a value. public func toResult(ev : L -> NSError) -> Result<R> { return either({ e in Result.Error(ev(e)) }, { v in .Value(Box(v)) }); } /// Much like the ?? operator for Optional types, takes a value and a function, /// and if the Either is Left, returns the value, otherwise maps the function over /// the value in Right and returns that value. public func fold<B>(value : B, f : R -> B) -> B { return either({ _ in value }, { r in f(r) }); }
Swadling on 9/06/2014. // Copyright (c) 2014 Maxwell Swadling. All rights reserved. // import class Foundation.NSError import typealias Foundation.NSErrorPointer /// Result is similar to an Either, except specialized to have an Error case that can /// only contain an NSError. public enum Result<V> { case Error(NSError) case Value(Box<V>) public init(_ e: NSError?, _ v: V) { if let ex = e { self = Result.Error(ex) } else { self = Result.Value(Box(v)) } } /// Converts a Result to a more general Either type. public func toEither() -> Either<NSError, V> { switch self { case let Error(e): return .Left(Box(e)) case let Value(v): return Either.Right(Box(v.value)) } }