Skip to content

Is it possible to add Switch with selector parameter ? #374

@Thaina

Description

@Thaina

public static partial class ObservableExtensions
{
public static Observable<T> Switch<T>(this Observable<Observable<T>> sources)
{
return new Switch<T>(sources);
}
}

public static partial class ObservableExtensions
{
    public static Observable<T> Switch<T>(this Observable<Observable<T>> sources)
    {
        return new Switch<T>(sources);
    }

    public static Observable<TResult> Switch<TSource, TResult>(this Observable<TSource> source, Func<TSource, Observable<TResult>> selector)
    {
        return new Switch<TResult>(source.Select(selector));
    }
}

//// usage

Observable<User> UserDataListener;
var servantListeners = UserDataListener.Switch((userData) => { // change when user data has changed
    return userData.ServantIDs.Select((servantID) => DataBase.Table("Servant").Listen(servantID));
});

Advantage :

  • cleaner API than Select->Switch for Observable chain
  • can be find easier in autocomplete

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions