<commit_before>//
//  Stream.swift
//  RxSwift
//
//  Created by <NAME> on 2014-06-25.
//  Copyright (c) 2014 GitHub. All rights reserved.
//

import Foundation

class Stream<T> {
	/*
	 * REQUIRED PRIMITIVES
	 */

	class func unit(value: T) -> Stream<T> {
		assert(false)
		return Stream()
	}

	func mapAccumulate<S, U>(initialState: S, _ f: (S, T) -> (S?, U)) -> Stream<U> {
		assert(false)
		return Stream<U>()
	}

	func merge<U>(evidence: Stream<T> -> Stream<Stream<U>>) -> Stream<U> {
		assert(false)
		return Stream<U>()
	}

	func switchToLatest<U>(evidence: Stream<T> -> Stream<Stream<U>>) -> Stream<U> {
		assert(false)
		return Stream<U>()
	}

	/*
	 * EXTENDED OPERATORS
	 */

	func map<U>(f: T -> U) -> Stream<U> {
		return mapAccumulate(nil) { (_, value) in
			return (nil, f(value))
		}
	}

	func scan<U>(initialValue: U, _ f: (U, T) -> U) -> Stream<U> {
		return mapAccumulate(initialValue) { (previous, current) in
			let mapped = f(previous, current)
			return (mapped, mapped)
		}
	}

	func take(count: Int) -> Stream<T> {
		return mapAccumulate(0) { (n, value) in
			let newN: Int? = (n + 1 < count ? n + 1 : nil)
			return (newN, value)
		}
	}<commit_msg>Fix map() terminating way too early<commit_after>//
//  Stream.swift
//  RxSwift
//
//  Created by <NAME> on 2014-06-25.
//  Copyright (c) 2014 GitHub. All rights reserved.
//

import Foundation

class Stream<T> {
	/*
	 * REQUIRED PRIMITIVES
	 */

	class func unit(value: T) -> Stream<T> {
		assert(false)
		return Stream()
	}

	func mapAccumulate<S, U>(initialState: S, _ f: (S, T) -> (S?, U)) -> Stream<U> {
		assert(false)
		return Stream<U>()
	}

	func merge<U>(evidence: Stream<T> -> Stream<Stream<U>>) -> Stream<U> {
		assert(false)
		return Stream<U>()
	}

	func switchToLatest<U>(evidence: Stream<T> -> Stream<Stream<U>>) -> Stream<U> {
		assert(false)
		return Stream<U>()
	}

	/*
	 * EXTENDED OPERATORS
	 */

	func map<U>(f: T -> U) -> Stream<U> {
		return mapAccumulate(()) { (_, value) in
			return ((), f(value))
		}
	}

	func scan<U>(initialValue: U, _ f: (U, T) -> U) -> Stream<U> {
		return mapAccumulate(initialValue) { (previous, current) in
			let mapped = f(previous, current)
			return (mapped, mapped)
		}
	}

	func take(count: Int) -> Stream<T> {
		return mapAccumulate(0) { (n, value) in
			let newN: Int? = (n + 1 < count ? n + 1 : nil)
			return (newN, value)
		}
	}
{'fraction_non_alphanumeric': 0.18697123519458544, 'fraction_numerical': 0.012690355329949238, 'mean_word_length': 3.1202090592334493, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 73, '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': '72021', 'n_tokens_mistral': 1034, 'n_tokens_neox': 923, 'n_words': 230}