 
 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 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").
+/// 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>)

	}
}

/// Applicative Functor `apply`. Given an Either<L, RA -> RB> and an Either<L,RA>,
/// returns an Either<L,RB>. If the `f` or `a' param is a Left, simply returns a Left with the
/// same value. Otherwise the function taken from Right(f) is applied to the value from Right(a)
/// And a Right is returned.
public func <*><L, RA, RB>(f: Either<L, RA -> RB>, a: Either<L, RA>) -> Either<L, RB> {
	switch (a, f) {
	case let (.Left(l), _): 

		return f(r.value)
	}
}

/// MARK: Equatable
public func ==<L: Equatable, R: Equatable>(lhs: Either<L, R>, rhs: Either<L, R>) -> Bool {
	switch (lhs, rhs) {
	case let (.Left(l), .Left(r)) where l.value == r.value:
		return true
	case let (.Right(l), .Right(r)) where l.value == r.value:
		return true
	default:
		return false
	}
}

public func !=<L: Equatable, R: Equatable>(lhs: Either<L, R>, rhs: Either<L, R>) -> Bool {
	return !(lhs == rhs)
}