RadicalZephyr / sodium-rust

FRP implementation in Rust
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Implement a version of `Stream::gate` that works specifically on `Cell<Option<T>>` #20

Open RadicalZephyr opened 7 months ago

RadicalZephyr commented 7 months ago

In Rust, it's common to explicitly represent nullable values using an Option. So far in my experiments with Sodium I have ended up having cells containing an option like this: Cell<Option<T>>. This is usually because I don't have a value when I create the Cell so I need to use a None. This imposes a cost down the line though because now every usage of this Cell needs to check if there is a value or not. Typically, these types of Cells are used similarly to a Cell<bool>, as a "gate" for certain Streams where I only want to allow a signal to pass if the Cell has data (or not sometimes).

I think that often rather than having a Cell<bool> to gate a stream, and then another Cell<Option<T>> it would be more convenient to have an operation to split a stream based on a Cell<Option<T>>, basically a s.snapshot(&opt_cell).split_opt() combinator...

Maybe this doesn't need to be explicitly implemented.