Q:

How to memorize previous payload in reactive extensions observable?

I have an IObservable boolObservable, the publisher acts like switch. There is also the variable currentItem with some value and the defaultItem containing pre-defined immutable value. Whenever 'true' is published, currentItem's value should be memorized, and currentItem should be set to defaultItem. When 'false' is published, currentItem's value should be changed to the previous one.
The easiest way to achieve this is to have the local variable. 
IObservable<bool> boolObservable;
string currentItem;
string defaultItem;

string local = null;
boolObservable.Subscribe(x =>
  {
    if (x) {
      local = currentItem;
      currentItem = defaultItem;
    }
    else
      currentItem = local;
  });

The problems begin when I have to repeat this several times and name local variable used for storage each time differentely. Is there a way to use Rx operators to "remember" not only the latest payload, but also the one before it?
UPD: @ibebbs' answer below is absolutely correct, Scan operator provides the necessary behavior:
var switchSource = new BehaviorSubject<bool>(false);
string currentItem = "FromDb";
string defaultItem = "Default";

switchSource
    .Skip(1)
    .Scan(string.Empty, (local, b) =>
    {
        if (b)
        {
            local = currentItem;
            currentItem = defaultItem;
        }
        else
            currentItem = local;

        return local;
    })
    .Subscribe();

Console.WriteLine($"Initial value: {currentItem}"); // FromDb
switchSource.OnNext(true);
Console.WriteLine($"Default value: {currentItem}"); // Default
switchSource.OnNext(false);
Console.WriteLine($"Initial value again: {currentItem}"); // FromDb
currentItem = "UserChanged";
Console.WriteLine($"UserChanged value: {currentItem}"); // UserChanged
switchSource.OnNext(true);
Console.WriteLine($"Default value: {currentItem}"); // Default
switchSource.OnNext(false);
Console.WriteLine($"UserChanged value again: {currentItem}"); // UserChanged

A:

You can use Scan to thread state through an observable sequence. For example:
public static IObservable<string> EitherItemOrDefault(IObservable<bool> switchSource, IObservable<string> itemSource, string defaultValue)
{
    return switchSource
        .WithLatestFrom(itemSource.StartWith(string.Empty), (switchValue, itemValue) => (Switch: switchValue, Item: itemValue))
        .Scan(
            (Current: string.Empty, Local: string.Empty),
            (seed, tuple) => tuple.Switch 
                            ? (Current: defaultValue, Local: tuple.Item) 
                            : (Current: seed.Local, Local: seed.Local))
        .Select(tuple => tuple.Current);
}

This takes an IObservable<bool> as your "switches" and an IObservable<string> as the items (currentItem in your example) and returns an IObservable<string> which will contain the defaultValue when switchSource emits a False and the last currentItem value when the switchSource emits a True.
Note: I may have got current and local backwards. It's late and your example neatly illustrates why global state should be avoided... it's just so tricky to reason about.

