<commit_before>import Dispatch
import Foundation
import enum Result.NoError

/// Represents an action that will do some work when executed with a value of
/// type `Input`, then return zero or more values of type `Output` and/or fail
/// with an error of type `Error`. If no failure should be possible, NoError can
/// be specified for the `Error` parameter.
///
/// Actions enforce serial execution. Any attempt to execute an action multiple
/// times concurrently will return an error.
public final class Action<Input, Output, Error: Swift.Error> {
	private let deinitToken: Lifetime.Token

	private let executeClosure: (_ state: Any, _ input: Input) -> SignalProducer<Output, Error>
	private let eventsObserver: Signal<Event<Output, Error>, NoError>.Observer
	private let disabledErrorsObserver: Signal<(), NoError>.Observer

	/// The lifetime of the Action.
	public let lifetime: Lifetime

	/// A signal of all events generated from applications of the Action.
	///
	/// In other words, this will send every `Event` from every signal generated
	/// by each SignalProducer returned from apply() except `ActionError.disabled`.
	public let events: Signal<Event<Output, Error>, NoError>

	/// A signal of all values generated from applications of the Action.
	///
	/// In other words, this will send every value from every signal generated
	/// by each SignalProducer returned from apply() except `ActionError.disabled`.
	public let values: Signal<Output, NoError>

	/// A signal of all errors generated from applications of the Action.
	///
	/// In other words, this will send errors from every signal generated by
	/// each SignalProducer returned from apply() except `ActionError.disabled`.
	public let errors: Signal<Error, NoError>

	/// A signal which is triggered by `ActionError.disabled`.
	public let disabledErrors: Signal<(), NoError>

	/// A signal of all completed events generated from applications of the action.
	///
	/// In other words, this will send completed events from every signal generated
	/// by each SignalProducer returned from apply().
	public let completed: Signal<(), NoError>

	/// Whether the action is currently executing.
	public let isExecuting: Property<Bool>

	/// Whether the action is currently enabled.
	public let isEnabled: Property<Bool>

	private let state: MutableProperty<ActionState>

	/// Initializes an action that will be conditionally enabled based on the
	/// value of `state`. Creates a `SignalProducer` for each input and the
	/// current value of `state`.
	///
	/// - note: `Action` guarantees that changes to `state` are observed in a
	///         thread-safe way. Thus, the value passed to `isEnabled` will
	///         always be identical to the value passed to `execute`, for each
	///         application of the action.
	///
	/// - note: This initializer should only be used if you need to provide
	///         custom input can also influence whether the action is enabled.
	///         The various convenience initializers should cover most use cases.
	///
	/// - parameters:
	///   - state: A property that provides the current state of the action
	///            whenever `apply()` is called.
	///   - enabledIf: A predicate that, given the current value of `state`,
	///                returns whether the action should be enabled.
	///   - execute: A closure that returns the `SignalProducer` returned by
	///              calling `apply(Input)` on the action, optionally using
	///              the current value of `state`.
	public init<State: PropertyProtocol>(state property: State, enabledIf isEnabled: @escaping (State.Value) -> Bool, _ execute: @escaping (State.Value, Input) -> SignalProducer<Output, Error>) {
		deinitToken = Lifetime.Token()
		lifetime = Lifetime(deinitToken)
<commit_msg>Make `Action` retain its state property.<commit_after>import Dispatch
import Foundation
import enum Result.NoError

/// Represents an action that will do some work when executed with a value of
/// type `Input`, then return zero or more values of type `Output` and/or fail
/// with an error of type `Error`. If no failure should be possible, NoError can
/// be specified for the `Error` parameter.
///
/// Actions enforce serial execution. Any attempt to execute an action multiple
/// times concurrently will return an error.
public final class Action<Input, Output, Error: Swift.Error> {
	private let deinitToken: Lifetime.Token

	private let executeClosure: (_ state: Any, _ input: Input) -> SignalProducer<Output, Error>
	private let eventsObserver: Signal<Event<Output, Error>, NoError>.Observer
	private let disabledErrorsObserver: Signal<(), NoError>.Observer

	/// The lifetime of the Action.
	public let lifetime: Lifetime

	/// A signal of all events generated from applications of the Action.
	///
	/// In other words, this will send every `Event` from every signal generated
	/// by each SignalProducer returned from apply() except `ActionError.disabled`.
	public let events: Signal<Event<Output, Error>, NoError>

	/// A signal of all values generated from applications of the Action.
	///
	/// In other words, this will send every value from every signal generated
	/// by each SignalProducer returned from apply() except `ActionError.disabled`.
	public let values: Signal<Output, NoError>

	/// A signal of all errors generated from applications of the Action.
	///
	/// In other words, this will send errors from every signal generated by
	/// each SignalProducer returned from apply() except `ActionError.disabled`.
	public let errors: Signal<Error, NoError>

	/// A signal which is triggered by `ActionError.disabled`.
	public let disabledErrors: Signal<(), NoError>

	/// A signal of all completed events generated from applications of the action.
	///
	/// In other words, this will send completed events from every signal generated
	/// by each SignalProducer returned from apply().
	public let completed: Signal<(), NoError>

	/// Whether the action is currently executing.
	public let isExecuting: Property<Bool>

	/// Whether the action is currently enabled.
	public let isEnabled: Property<Bool>

	private let state: MutableProperty<ActionState>

	/// Initializes an action that will be conditionally enabled based on the
	/// value of `state`. Creates a `SignalProducer` for each input and the
	/// current value of `state`.
	///
	/// - note: `Action` guarantees that changes to `state` are observed in a
	///         thread-safe way. Thus, the value passed to `isEnabled` will
	///         always be identical to the value passed to `execute`, for each
	///         application of the action.
	///
	/// - note: This initializer should only be used if you need to provide
	///         custom input can also influence whether the action is enabled.
	///         The various convenience initializers should cover most use cases.
	///
	/// - parameters:
	///   - state: A property that provides the current state of the action
	///            whenever `apply()` is called.
	///   - enabledIf: A predicate that, given the current value of `state`,
	///                returns whether the action should be enabled.
	///   - execute: A closure that returns the `SignalProducer` returned by
	///              calling `apply(Input)` on the action, optionally using
	///              the current value of `state`.
	public init<State: PropertyProtocol>(state property: State, enabledIf isEnabled: @escaping (State.Value) -> Bool, _ execute: @escaping (State.Value, Input) -> SignalProducer<Output, Error>) {
		deinitToken = Lifetime.Token()
		lifetime = Lifetime(deinitToken)
		
		// Retain the `property` for the created `Action`.
		lifetime.ended.observeCompleted { _ = property }

{'fraction_non_alphanumeric': 0.09642484342379959, 'fraction_numerical': 0.0, 'mean_word_length': 3.2701949860724233, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 41, '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': '72039', 'n_tokens_mistral': 1987, 'n_tokens_neox': 1897, 'n_words': 926}