<commit_before># Basic Operators

This document explains some of the most common operators used in ReactiveCocoa,
and includes examples demonstrating their use.

Operators that apply to [sequences][Sequences] _and_ [signals][Signals] are
known as [stream][Streams] operators.

**[Performing side effects with signals](#performing-side-effects-with-signals)**

 1. [Subscription](#subscription)
 1. [Injecting effects](#injecting-effects)

**[Transforming streams](#transforming-streams)**

 1. [Mapping](#mapping)
 1. [Filtering](#filtering)

**[Combining streams](#combining-streams)**

 1. [Concatenating](#concatenating)
 1. [Flattening](#flattening)
 1. [Mapping and flattening](#mapping-and-flattening)

**[Combining signals](#combining-signals)**

 1. [Sequencing](#sequencing)
 1. [Merging](#merging)
 1. [Combining latest values](#combining-latest-values)
 1. [Switching](#switching)

## Performing side effects with signals

Most signals start out "cold," which means that they will not do any work until
[subscription](#subscription).

Upon subscription, a signal or its [subscribers][Subscription] can perform _side
effects_, like logging to the console, making a network request, updating the
user interface, etc.

Side effects can also be [injected](#injecting-effects) into a signal, where
they won't be performed immediately, but will instead take effect with each
subscription later.

### Subscription

The [-subscribe…][RACSignal] methods give you access to the current and future values in a signal:

```objc
RACSignal *letters = [@"A B C D E F G H I" componentsSeparatedByString:@" "].rac_sequence.signal;

// Outputs: A B C D
[letters subscribeNext:^(NSString *x) {
    NSLog(@"%@", x);
}];
```

For a cold signal, side effects will be performed once _per subscription_:

```objc
__block unsigned subscriptions = 0;

RACSignal *loggingSignal = [RACSignal createSignal:^ RACDisposable * (id<RACSubscriber> subscriber) {
    subscriptions++;
    [subscriber sendCompleted];
    return nil;
}];

// Outputs:
// subscription 1
[loggingSignal subscribeCompleted:^{
    NSLog(@"subscription %u", subscriptions);
}];

// Outputs:<commit_msg>Correct example output in BasicOperators.md<commit_after># Basic Operators

This document explains some of the most common operators used in ReactiveCocoa,
and includes examples demonstrating their use.

Operators that apply to [sequences][Sequences] _and_ [signals][Signals] are
known as [stream][Streams] operators.

**[Performing side effects with signals](#performing-side-effects-with-signals)**

 1. [Subscription](#subscription)
 1. [Injecting effects](#injecting-effects)

**[Transforming streams](#transforming-streams)**

 1. [Mapping](#mapping)
 1. [Filtering](#filtering)

**[Combining streams](#combining-streams)**

 1. [Concatenating](#concatenating)
 1. [Flattening](#flattening)
 1. [Mapping and flattening](#mapping-and-flattening)

**[Combining signals](#combining-signals)**

 1. [Sequencing](#sequencing)
 1. [Merging](#merging)
 1. [Combining latest values](#combining-latest-values)
 1. [Switching](#switching)

## Performing side effects with signals

Most signals start out "cold," which means that they will not do any work until
[subscription](#subscription).

Upon subscription, a signal or its [subscribers][Subscription] can perform _side
effects_, like logging to the console, making a network request, updating the
user interface, etc.

Side effects can also be [injected](#injecting-effects) into a signal, where
they won't be performed immediately, but will instead take effect with each
subscription later.

### Subscription

The [-subscribe…][RACSignal] methods give you access to the current and future values in a signal:

```objc
RACSignal *letters = [@"A B C D E F G H I" componentsSeparatedByString:@" "].rac_sequence.signal;

// Outputs: A B C D E F G H I
[letters subscribeNext:^(NSString *x) {
    NSLog(@"%@", x);
}];
```

For a cold signal, side effects will be performed once _per subscription_:

```objc
__block unsigned subscriptions = 0;

RACSignal *loggingSignal = [RACSignal createSignal:^ RACDisposable * (id<RACSubscriber> subscriber) {
    subscriptions++;
    [subscriber sendCompleted];
    return nil;
}];

// Outputs:
// subscription 1
[loggingSignal subscribeCompleted:^{
    NSLog(@"subscription %u", subscriptions);
}];

// Outputs:
{'fraction_non_alphanumeric': 0.12304507819687213, 'fraction_numerical': 0.005979760809567618, 'mean_word_length': 5.52023988005997, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3843506', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1253, 'n_words': 446}