Skip to content

filter taking into account value of previous elements: (how) can it be done? #927

Answered by JakenVeina
shimpe asked this question in Q&A
Discussion options

You must be logged in to vote

You want .FilterOnObservable(). Something along the lines of...

using var source = new SourceCache<long, Item>()
{
    new Item()
    {
        Id = 1,
        Value = 1
    },
    new Item()
    {
        Id = 2,
        Value = 2
    },
    new Item()
    {
        Id = 3,
        Value = 3,
        ParentId = 2,
        ParentValue = 1
    },
    new Item()
    {
        Id = 4,
        Value = 4,
        ParentId = 2,
        ParentValue 2
    }
};

using var subscription = source
    .Connect()
    .FilterOnObservable(item => (item.ParentId is long parentId)
        ? source
            .Watch(parentId)
            .Select(parentChange => parentChange.Current.Value == item.ParentValue)

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@shimpe
Comment options

@shimpe
Comment options

@JakenVeina
Comment options

@shimpe
Comment options

Answer selected by shimpe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants