<commit_before>//  Copyright (c) 2014 <NAME>. All rights reserved.

/// A type representing an alternative of one of two types.
///
/// By convention, and where applicable, `Left` is used to indicate failure, while `Right` is used to indicate success. (Mnemonic: “right” is a synonym for “correct.”)
///
/// Otherwise, it is implied that `Left` and `Right` are effectively unordered alternatives of equal standing.
public enum Either<T, U>: EitherType, Printable {
	case Left(Box<T>)
	case Right(Box<U>)


	// MARK: Lifecycle

	/// Constructs a `Left`.
	///
	/// Suitable for partial application.
	public static func left(value: T) -> Either {
		return Left(Box(value))
	}

	/// Constructs a `Right`.
	///
	/// Suitable for partial application.
	public static func right(value: U) -> Either {
		return Right(Box(value))
	}


	// MARK: API

	/// Returns the result of applying `f` to the value of `Left`, or `g` to the value of `Right`.
	public func either<V>(f: T -> V, _ g: U -> V) -> V {
		switch self {
		case let .Left(x):
			return f(x.value)
		case let .Right(x):
			return g(x.value)
		}
	}

	/// Maps `Right` instances with `f`, and returns `Left` instances as-is.
	public func map<V>(f: U -> V) -> Either<T, V> {
		return either(Either<T, V>.left, f >>> Either<T, V>.right)
	}


	/// Returns the value of `Left` instances, or `nil` for `Right` instances.
	public var left: T? {
		return either(id, const(nil))
	}

	/// Returns the value of `Right` instances, or `nil` for `Left` instances.
	public var right: U? {
		return either(const(nil), id)
	}


	// MARK: Printable

	public var description: String {
		return either({ ".Left(\($0))"}, { ".Right(\($0))" })
	}
}


// MARK: Imports

import Box
import Prelude<commit_msg>Define the operator.<commit_after>//  Copyright (c) 2014 <NAME>. All rights reserved.

/// A type representing an alternative of one of two types.
///
/// By convention, and where applicable, `Left` is used to indicate failure, while `Right` is used to indicate success. (Mnemonic: “right” is a synonym for “correct.”)
///
/// Otherwise, it is implied that `Left` and `Right` are effectively unordered alternatives of equal standing.
public enum Either<T, U>: EitherType, Printable {
	case Left(Box<T>)
	case Right(Box<U>)


	// MARK: Lifecycle

	/// Constructs a `Left`.
	///
	/// Suitable for partial application.
	public static func left(value: T) -> Either {
		return Left(Box(value))
	}

	/// Constructs a `Right`.
	///
	/// Suitable for partial application.
	public static func right(value: U) -> Either {
		return Right(Box(value))
	}


	// MARK: API

	/// Returns the result of applying `f` to the value of `Left`, or `g` to the value of `Right`.
	public func either<V>(f: T -> V, _ g: U -> V) -> V {
		switch self {
		case let .Left(x):
			return f(x.value)
		case let .Right(x):
			return g(x.value)
		}
	}

	/// Maps `Right` instances with `f`, and returns `Left` instances as-is.
	public func map<V>(f: U -> V) -> Either<T, V> {
		return either(Either<T, V>.left, f >>> Either<T, V>.right)
	}


	/// Returns the value of `Left` instances, or `nil` for `Right` instances.
	public var left: T? {
		return either(id, const(nil))
	}

	/// Returns the value of `Right` instances, or `nil` for `Left` instances.
	public var right: U? {
		return either(const(nil), id)
	}


	// MARK: Printable

	public var description: String {
		return either({ ".Left(\($0))"}, { ".Right(\($0))" })
	}
}


infix operator >>- {
	associativity left
	precedence 150
}


// MARK: Imports

import Box
import Prelude
{'fraction_non_alphanumeric': 0.15789473684210525, 'fraction_numerical': 0.004244482173174873, 'mean_word_length': 3.0819861431870668, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2085918', 'n_tokens_mistral': 1243, 'n_tokens_neox': 1154, 'n_words': 439}