<commit_before>public class Promise<T> : CustomStringConvertible {
	private var value: T?
	private var handlers: [T -> ()]
	
	public init(_ value: T) {
		self.value = value
		handlers = []
	}
	
	public init(_ executor: (resolve: Promise<T> -> ()) -> ()) {
		handlers = []
		executor(resolve: resolve)
	}
	
	private func resolve(promise: Promise<T>) {
		promise.`defer` {
			if self.value != nil {
				return
			}
			self.value = $0
			
			for handler in self.handlers {
				handler($0)
			}
			self.handlers.removeAll(keepCapacity: false)
		}
	}
	
	private func `defer`(handler: T -> ()) {
		if let value = self.value {
			handler(value)
		} else {
			handlers.append(handler)
		}
	}
	
	public func map<U>(f: T -> U) -> Promise<U> {
		return flatMap { Promise<U>(f($0)) }
	}
	
	public func flatMap<U>(f: T -> Promise<U>) -> Promise<U> {
		return Promise<U>({ resolve in self.`defer` { resolve(f($0)) } })
	}
	
	public var description: String {
		if let value = self.value {
			return "Promise(\(value))"
		} else {
			return "Promise"
		}
	}
}

public func map<T, U>(x: Promise<T>, f: T -> U) -> Promise<U> {
	return x.map(f)
}

public func flatMap<T, U>(x: Promise<T>, f: T -> Promise<U>) -> Promise<U> {
	return x.flatMap(f)
}

public func flatten<T>(x: Promise<Promise<T>>) -> Promise<T> {
	return x.flatMap { $0 }
}

infix operator >>- { associativity left precedence 100 }

public func >>-<T, U>(lhs: Promise<T>, rhs: T -> Promise<U>) -> Promise<U> {
	return lhs.flatMap(rhs)
}

public func >>-<T, U>(lhs: Promise<T?>, rhs: T? -> Promise<U?>?) -> Promise<U?> {
	return lhs.flatMap { rhs($0) ?? Promise(nil) }
}<commit_msg>Remove the global `map` and `flatMap` functions<commit_after>public class Promise<T> : CustomStringConvertible {
	private var value: T?
	private var handlers: [T -> ()]
	
	public init(_ value: T) {
		self.value = value
		handlers = []
	}
	
	public init(_ executor: (resolve: Promise<T> -> ()) -> ()) {
		handlers = []
		executor(resolve: resolve)
	}
	
	private func resolve(promise: Promise<T>) {
		promise.`defer` {
			if self.value != nil {
				return
			}
			self.value = $0
			
			for handler in self.handlers {
				handler($0)
			}
			self.handlers.removeAll(keepCapacity: false)
		}
	}
	
	private func `defer`(handler: T -> ()) {
		if let value = self.value {
			handler(value)
		} else {
			handlers.append(handler)
		}
	}
	
	public func map<U>(f: T -> U) -> Promise<U> {
		return flatMap { Promise<U>(f($0)) }
	}
	
	public func flatMap<U>(f: T -> Promise<U>) -> Promise<U> {
		return Promise<U>({ resolve in self.`defer` { resolve(f($0)) } })
	}
	
	public var description: String {
		if let value = self.value {
			return "Promise(\(value))"
		} else {
			return "Promise"
		}
	}
}

public func flatten<T>(x: Promise<Promise<T>>) -> Promise<T> {
	return x.flatMap { $0 }
}

infix operator >>- { associativity left precedence 100 }

public func >>-<T, U>(lhs: Promise<T>, rhs: T -> Promise<U>) -> Promise<U> {
	return lhs.flatMap(rhs)
}

public func >>-<T, U>(lhs: Promise<T?>, rhs: T? -> Promise<U?>?) -> Promise<U?> {
	return lhs.flatMap { rhs($0) ?? Promise(nil) }
}
{'fraction_non_alphanumeric': 0.1849822752175314, 'fraction_numerical': 0.005800837898807605, 'mean_word_length': 3.2578875171467763, 'pattern_counts': {'":': 0, '<': 54, '<?xml version=': 0, '>': 96, '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': '7110111', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1154, 'n_words': 284}