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

/// Identity; returns its argument.
public func id<T>(x: T) -> T {
	return x
}

/// Returns a fixpoint of a function f, i.e. a value x for which f(x) returns x.
///
/// This is used to make recursive reduce() from nonrecursive reduceLeft().
public func fix<A, B>(f: (A -> B) -> A -> B) -> A -> B {
	return { x in f(fix(f))(x) }
}


infix operator .. { associativity right }

/// Unary function composition.
public func .. <T, U, V>(f: U -> V, g: T -> U) -> T -> V {
	return { f(g($0)) }
}


/// Unary/binary function composition (curried).
public func .. <T, U, V, W>(f: V -> W, g: T -> U -> V) -> (T, U) -> W {
	return uncurry { f .. g($0) }
}

/// Unary/binary function composition (uncurried).
public func .. <T, U, V, W>(f: V -> W, g: (T, U) -> V) -> (T, U) -> W {
	return f .. curry(g)
}

/// Binary/unary function composition (curried).
public func .. <T, U, V, W>(f: U -> V -> W, g: T -> U) -> (T, V) -> W {
	return uncurry(f .. g)
}

/// Binary/unary function composition (uncurried).
public func .. <T, U, V, W>(f: (U, V) -> W, g: T -> U) -> (T, V) -> W {
	return curry(f) .. g
}


/// Binary/binary function composition (curried, curried).
public func .. <T, U, V, W, X>(f: V -> W -> X, g: T -> U -> V) -> (T, U, W) -> X {
	return uncurry { f .. g($0) }
}

/// Binary/binary function composition (curried, uncurried).
public func .. <T, U, V, W, X>(f: V -> W -> X, g: (T, U) -> V) -> (T, U, W) -> X {
	return f .. curry(g)
}

/// Binary/binary function composition (uncurried, curried).
public func .. <T, U, V, W, X>(f: (V, W) -> X, g: T -> U -> V) -> (T, U, W) -> X {
	return curry(f) .. g
}

/// Binary/binary function composition (uncurried, uncurried).
public func .. <T, U, V, W, X>(f: (V, W) -> X, g: (T, U) -> V) -> (T, U, W) -> X {
	return curry(f) .. curry(g)
}
<commit_msg>Binary currying & uncurrying.<commit_after>//  Copyright (c) 2014 <NAME>. All rights reserved.

/// Identity; returns its argument.
public func id<T>(x: T) -> T {
	return x
}

/// Returns a fixpoint of a function f, i.e. a value x for which f(x) returns x.
///
/// This is used to make recursive reduce() from nonrecursive reduceLeft().
public func fix<A, B>(f: (A -> B) -> A -> B) -> A -> B {
	return { x in f(fix(f))(x) }
}


infix operator .. { associativity right }

/// Unary function composition.
public func .. <T, U, V>(f: U -> V, g: T -> U) -> T -> V {
	return { f(g($0)) }
}


/// Unary/binary function composition (curried).
public func .. <T, U, V, W>(f: V -> W, g: T -> U -> V) -> (T, U) -> W {
	return uncurry { f .. g($0) }
}

/// Unary/binary function composition (uncurried).
public func .. <T, U, V, W>(f: V -> W, g: (T, U) -> V) -> (T, U) -> W {
	return f .. curry(g)
}

/// Binary/unary function composition (curried).
public func .. <T, U, V, W>(f: U -> V -> W, g: T -> U) -> (T, V) -> W {
	return uncurry(f .. g)
}

/// Binary/unary function composition (uncurried).
public func .. <T, U, V, W>(f: (U, V) -> W, g: T -> U) -> (T, V) -> W {
	return curry(f) .. g
}


/// Binary/binary function composition (curried, curried).
public func .. <T, U, V, W, X>(f: V -> W -> X, g: T -> U -> V) -> (T, U, W) -> X {
	return uncurry { f .. g($0) }
}

/// Binary/binary function composition (curried, uncurried).
public func .. <T, U, V, W, X>(f: V -> W -> X, g: (T, U) -> V) -> (T, U, W) -> X {
	return f .. curry(g)
}

/// Binary/binary function composition (uncurried, curried).
public func .. <T, U, V, W, X>(f: (V, W) -> X, g: T -> U -> V) -> (T, U, W) -> X {
	return curry(f) .. g
}

/// Binary/binary function composition (uncurried, uncurried).
public func .. <T, U, V, W, X>(f: (V, W) -> X, g: (T, U) -> V) -> (T, U, W) -> X {
	return curry(f) .. curry(g)
}


/// Binary currying.
public func curry<T, U, V>(f: (T, U) -> V) -> T -> U -> V {
	return { x in { y in f(x, y) } }
}

/// Binary uncurrying.
public func uncurry<T, U, V>(f: T -> U -> V) -> (T, U) -> V {
	return { x, y in
		f(x)(y)
	}
}

{'fraction_non_alphanumeric': 0.240824534942182, 'fraction_numerical': 0.003519356460532931, 'mean_word_length': 2.2911497105045493, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 133, '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': '201433', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1615, 'n_words': 588}