//  Copyright (c) 2015 Rob Rix. All rights reserved.

public enum Value: Printable {
	case Constant(Any)
	case Function(Any -> Any)

	public func destructure<T, U, V, W>(constant: T -> W, _ function: (U -> V) -> W) -> W {
		switch self {
		case let Constant(v):
			return constant(v as T)
		case let Function(f):
			return function(f as U -> Any as U -> V)
		}
	}


	// MARK: Printable

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

//  Copyright (c) 2015 Rob Rix. All rights reserved.

public enum Value: Printable {
	case Constant(Any)
	case Function(Any -> Any)

	public func destructure<T, U, V, W>(constant: T -> W, _ function: (U -> V) -> W) -> W? {
		switch self {
		case let Constant(v as T):
			return constant(v as T)
		case let Function(f):
			return function(f as U -> Any as U -> V)
		default:
			return nil
		}
	}


	// MARK: Printable

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

Work around a runtime crash.
Work around a runtime crash.
