<commit_before>//  Copyright © 2016 <NAME>. All rights reserved.

// MARK: - ReaderType

public protocol ReaderType: Pointed {
	associatedtype EnvR
	associatedtype ValueR
	
	var run: EnvR -> ValueR { get }
	init(_ run: EnvR -> ValueR)
	
	var reader: Reader<EnvR, ValueR> { get }
}

// MARK: - ReaderType: Pointed

public extension ReaderType {
	public typealias PointedValue = EnvR -> ValueR
	
	public static func pure(a: EnvR -> ValueR) -> Self {
		return Self.init(a)
	}
}

// MARK: - ReaderType - method

public extension ReaderType {
	public func local(f: EnvR -> EnvR) -> Self {
		return Self.init { self.run(f($0)) }
	}
}

// MARK: - ReaderType - map/flatMap

public extension ReaderType {
	public func map<Value2>(f: ValueR -> Value2) -> Reader<EnvR, Value2> {
		return Reader { f(self.run($0)) }
	}
	
	public func flatMap<Value2>(fn: ValueR -> Reader<EnvR, Value2>) -> Reader<EnvR, Value2> {
		return Reader { fn(self.run($0)).run($0) }
	}
}

/// Alias for `map(f:)`
public func <^> <R, A, B, RT: ReaderType where RT.EnvR == R, RT.ValueR == A>(f: A -> B, g: RT) -> Reader<R, B> {
	return g.map(f)
}

/// Alias for `flatMap(g:)`
public func >>- <R, A, B, RT: ReaderType where RT.EnvR == R, RT.ValueR == A>(m: RT, fn: A -> Reader<R, B>) -> Reader<R, B> {
	return m.flatMap(fn)
}

// MARK: - ReaderType (ValueR: OptionalType) - map/flatMap

public extension ReaderType where ValueR: OptionalType {
	public func map<Value2>(f: ValueR.Wrapped -> Value2) -> Reader<EnvR, Value2?> {
		return Reader { f <^> self.run($0) }
	}
	
	public func flatMap<Value2>(fn: ValueR.Wrapped -> Reader<EnvR, Value2>) -> Reader<EnvR, Value2?> {
		return Reader { (self.run($0) >>- fn)?.run($0) }
	}
}

/// Alias for `map(f:)`
public func <^> <R, A: OptionalType, B, RT: ReaderType where RT.EnvR == R, RT.ValueR == A>(f: A -> B, g: RT) -> Reader<R, B?> {
	return g.map(f)
}

/// Alias for `flatMap(fn:)`
public func >>- <R, A: OptionalType, B, RT: ReaderType where RT.EnvR == R, RT.ValueR == A>(m: RT, fn: A.Wrapped -> Reader<R, B>) -> Reader<R, B?> {
	return m.flatMap(fn)
}

// MARK: - Reader

public struct Reader<R, A> {
	public let run: R -> A
}

// MARK: - Reader: ReaderType

extension Reader: ReaderType {
	public init(_ run: R -> A) {
		self.run = run
	}
	
	public var reader: Reader<R, A> {
		return self
	}
}

// MARK: - Reader: Pointed

public extension Reader {
	public typealias PointedValue = R -> A
}
<commit_msg>Add ask/asks (Reader)<commit_after>//  Copyright © 2016 <NAME>. All rights reserved.

// MARK: - ReaderType

public protocol ReaderType: Pointed {
	associatedtype EnvR
	associatedtype ValueR
	
	var run: EnvR -> ValueR { get }
	init(_ run: EnvR -> ValueR)
	
	var reader: Reader<EnvR, ValueR> { get }
}

// MARK: - ReaderType: Pointed

public extension ReaderType {
	public typealias PointedValue = EnvR -> ValueR
	
	public static func pure(a: EnvR -> ValueR) -> Self {
		return Self.init(a)
	}
}

// MARK: - ReaderType - method

public extension ReaderType {
	public func local(f: EnvR -> EnvR) -> Self {
		return Self.init { self.run(f($0)) }
	}
}

// MARK: - ReaderType - map/flatMap

public extension ReaderType {
	public func map<Value2>(f: ValueR -> Value2) -> Reader<EnvR, Value2> {
		return Reader { f(self.run($0)) }
	}
	
	public func flatMap<Value2>(fn: ValueR -> Reader<EnvR, Value2>) -> Reader<EnvR, Value2> {
		return Reader { fn(self.run($0)).run($0) }
	}
}

/// Alias for `map(f:)`
public func <^> <R, A, B, RT: ReaderType where RT.EnvR == R, RT.ValueR == A>(f: A -> B, g: RT) -> Reader<R, B> {
	return g.map(f)
}

/// Alias for `flatMap(g:)`
public func >>- <R, A, B, RT: ReaderType where RT.EnvR == R, RT.ValueR == A>(m: RT, fn: A -> Reader<R, B>) -> Reader<R, B> {
	return m.flatMap(fn)
}

// MARK: - ReaderType (ValueR: OptionalType) - map/flatMap

public extension ReaderType where ValueR: OptionalType {
	public func map<Value2>(f: ValueR.Wrapped -> Value2) -> Reader<EnvR, Value2?> {
		return Reader { f <^> self.run($0) }
	}
	
	public func flatMap<Value2>(fn: ValueR.Wrapped -> Reader<EnvR, Value2>) -> Reader<EnvR, Value2?> {
		return Reader { (self.run($0) >>- fn)?.run($0) }
	}
}

/// Alias for `map(f:)`
public func <^> <R, A: OptionalType, B, RT: ReaderType where RT.EnvR == R, RT.ValueR == A>(f: A -> B, g: RT) -> Reader<R, B?> {
	return g.map(f)
}

/// Alias for `flatMap(fn:)`
public func >>- <R, A: OptionalType, B, RT: ReaderType where RT.EnvR == R, RT.ValueR == A>(m: RT, fn: A.Wrapped -> Reader<R, B>) -> Reader<R, B?> {
	return m.flatMap(fn)
}

// MARK: - Reader

public struct Reader<R, A> {
	public let run: R -> A
}

// MARK: - Reader: ReaderType

extension Reader: ReaderType {
	public init(_ run: R -> A) {
		self.run = run
	}
	
	public var reader: Reader<R, A> {
		return self
	}
}

// MARK: - Reader: Pointed

public extension Reader {
	public typealias PointedValue = R -> A
}

// MARK: - Functions

/// Fetch the value of the environment
public func ask<R>() -> Reader<R, R> {
	return Reader(id)
}

/// Retrieve a function of the current environment.
public func asks<R, A>(f: R -> A) -> Reader<R, A> {
	return Reader(f)
}

{'fraction_non_alphanumeric': 0.17845184163876304, 'fraction_numerical': 0.009060468780776048, 'mean_word_length': 3.270815811606392, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 128, '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': '2606509', 'n_tokens_mistral': 2075, 'n_tokens_neox': 1910, 'n_words': 566}