Skip to content

Why BehaviorSubject requires default value? #1364

@lexer

Description

@lexer

I often need BehaviorSubject that don't have default value and should not spawn values until first value is supplied.

Currently as a workaround I initialize it with null and provide access to it after filter that ignores null value. Which looks ugly.

private BehaviorSubject<Location> locationUpdateSubject = BehaviorSubject.create((Location) null);

    public Observable<Location> getLocationUpdates() {
        return locationUpdateSubject.filter(new Func1<Location, Boolean>() {
            @Override
            public Boolean call(Location location) {
                return location != null;
            }
        });
    }

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