Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Signal.filter #73

@dylemma

Description

@dylemma

Some discussion in #59 led to talk about Signal.filter, which ended with a question:
what needs to happen to a Signal when you filter it?

I posted:

Filtered stream ignores unaccepted changes

[parent] 1---2---3---4---5---
[evens ] ----2-------4-------

But this is bad because a) it leaves the filtered stream with the possibility of having no >initial value and b) it doesn't make a ton of sense in terms of signals.

Filtering a stream results in a Signalof Options

def filter(f: T => Boolean): Signal[Option[T]]

This kind of works, but it's different from the usual semantics of filter, and that could be >confusing.

Signal's value is always optional
Where there exists some ADT for the signal's now, along the lines of

sealed trait State[+T]
case object Undefined extends State[Nothing]
case class Defined[T](value: T) extends State[T]

And where a filtered signal's parent changed to a value that its filter didn't accept, its own value would go to Undefined

I am of the opinion that using the State data type under the hood is the best idea, though it would bring about some necessary changes:

//in the Signal trait...
def changes: EventStream[State[T]]
def definedChanges: EventStream[T] = changes collect {
  case Defined(t) => t
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions