add a map method to signal

This commit is contained in:
Evan Almloff committed 2023-10-11 12:46:53 -05:00
1 parent 3578f03f4f
commit 7ea868bd08
1 file changed
+6
+6
View File
@@ -1,3 +1,4 @@
use crate::SignalMap;
use std::{
cell::{Ref, RefCell, RefMut},
ops::{Deref, DerefMut},
@@ -252,6 +253,11 @@ impl<T: 'static> Signal<T> {
let mut write = self.write();
f(&mut *write)
}
/// Map the signal to a new type.
pub fn map<O>(self, f: fn(&T) -> &O) -> SignalMap<T, O> {
SignalMap::new(self, f)
}
}
impl<T: Clone + 'static> Signal<T> {