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

public enum Value: Printable {
	public init(constant: Any) {
		self = Constant(Box(constant))
	}

	public init<T, U>(function: T -> U) {
		self = Function(Box(function))
	}

	case Constant(Box<Any>)
	case Function(Box<Any>)

	public func constant<T>() -> T? {
		switch self {
		case let Constant(v):
			return v.value as? T
		default:
			return nil
		}
	}

	public func function<T, U>() -> (T -> U)? {
		switch self {
		case let Function(f):
			return f.value as? T -> U
		default:
			return nil
		}
	}


	public func apply(argument: Value) -> Value? {
		return (function() as (Any -> Any)?)
			.map { argument.constant().map($0) }
			.map { Value(constant: $0) }
	}


	// MARK: Printable

	public var description: String {
		switch self {
		case let Constant(c):
			return ".Constant(\(toString(c)))"
		case let Function(f):
			return ".Function(\(toString(f)))"
		}
	}
}


// MARK: - Imports

import Box<commit_msg>Flatten ?? down to ? before wrapping.<commit_after>//  Copyright (c) 2015 <NAME>. All rights reserved.

public enum Value: Printable {
	public init(constant: Any) {
		self = Constant(Box(constant))
	}

	public init<T, U>(function: T -> U) {
		self = Function(Box(function))
	}

	case Constant(Box<Any>)
	case Function(Box<Any>)

	public func constant<T>() -> T? {
		switch self {
		case let Constant(v):
			return v.value as? T
		default:
			return nil
		}
	}

	public func function<T, U>() -> (T -> U)? {
		switch self {
		case let Function(f):
			return f.value as? T -> U
		default:
			return nil
		}
	}


	public func apply(argument: Value) -> Value? {
		return (function() as (Any -> Any)?)
			.map { argument.constant().map($0) }?
			.map { Value(constant: $0) }
	}


	// MARK: Printable

	public var description: String {
		switch self {
		case let Constant(c):
			return ".Constant(\(toString(c)))"
		case let Function(f):
			return ".Function(\(toString(f)))"
		}
	}
}


// MARK: - Imports

import Box
{'fraction_non_alphanumeric': 0.16290726817042606, 'fraction_numerical': 0.006015037593984963, 'mean_word_length': 3.024193548387097, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 29, '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': '879899', 'n_tokens_mistral': 786, 'n_tokens_neox': 690, 'n_words': 203}