pub fn create_reducer<F, Out, Msg>(initial: Out, reduce: F) -> (ReadSignal<Out>, Rc<impl Fn(Msg)>)
where
    F: Fn(&Out, Msg) -> Out,
{
    let memo = Signal::new(initial);

    let dispatcher = {
        let memo = memo.clone();
        move |msg| {
            memo.set(reduce(&memo.get_untracked(), msg));
        }
    };

    (memo.into_handle(), Rc::new(dispatcher))
}
/// An alternative to [`Signal::new`] that uses a reducer to get the next value.
///
/// It uses a reducer function that takes the previous value and a message and returns the next
/// value.
///
/// Returns a [`ReadSignal`] and a dispatch function to send messages to the reducer.
///
/// # Params
/// * `initial` - The initial value of the state.
/// * `reducer` - A function that takes the previous value and a message and returns the next value.
///
/// # Example
/// ```
/// use sycamore_reactive::*;
///
/// enum Msg {
///     Increment,
///     Decrement,
/// }
///
/// let (state, dispatch) = create_reducer(0, |state, msg: Msg| match msg {
///     Msg::Increment => *state + 1,
///     Msg::Decrement => *state - 1,
/// });
///
/// assert_eq!(*state.get(), 0);
/// dispatch(Msg::Increment);
/// assert_eq!(*state.get(), 1);
/// dispatch(Msg::Decrement);
/// assert_eq!(*state.get(), 0);
/// ```
An alternative to [`Signal::new`] that uses a reducer to get the next value.
It uses a reducer function that takes the previous value and a message and returns the next
value.

Returns a [`ReadSignal`] and a dispatch function to send messages to the reducer.
An alternative to [ ` Signal :: new ` ] that uses a reducer to get the next value . It uses a reducer function that takes the previous value and a message and returns the next value . Returns a [ ` ReadSignal ` ] and a dispatch function to send messages to the reducer .
pub fn create_reducer<F, Out, Msg>(initial: Out, reduce: F) -> (ReadSignal<Out>, Rc<impl Fn(Msg)>)
where
    F: Fn(&Out, Msg) -> Out,
{
    let memo = Signal::new(initial);
    let dispatcher = {
        let memo = memo.clone();
        move |msg| {
            memo.set(reduce(&memo.get_untracked(), msg));
        }
    };
    (memo.into_handle(), Rc::new(dispatcher))
}
pub fn create_reducer < F , Out , Msg > ( initial : Out , reduce : F ) -> ( ReadSignal < Out > , Rc < impl Fn ( Msg ) > ) where F : Fn ( & Out , Msg ) -> Out , { let memo = Signal :: new ( initial ) ; let dispatcher = { let memo = memo . clone ( ) ; move | msg | { memo . set ( reduce ( & memo . get_untracked ( ) , msg ) ) ; } } ; ( memo . into_handle ( ) , Rc :: new ( dispatcher ) ) }
An alternative to [`Signal::new`] that uses a reducer to get the next value.
An alternative to [ ` Signal :: new ` ] that uses a reducer to get the next value .
initial
Out
reduce
F
params
`initial` - The initial value of the state.
`reducer` - A function that takes the previous value and a message and returns the next value.
` initial ` - The initial value of the state . ` reducer ` - A function that takes the previous value and a message and returns the next value .
example
```
use sycamore_reactive::*.

enum Msg {
Increment,
Decrement,
}

let (state, dispatch) = create_reducer(0, |state, msg: Msg| match msg {
Msg::Increment => *state + 1,
Msg::Decrement => *state - 1,
}).

assert_eq!(*state.get(), 0);
dispatch(Msg::Increment);
assert_eq!(*state.get(), 1);
dispatch(Msg::Decrement);
assert_eq!(*state.get(), 0);
```
` ` ` use sycamore_reactive :: * . enum Msg { Increment Decrement } let ( state dispatch ) = create_reducer ( 0 |state msg : Msg| match msg { Msg :: Increment = > * state + 1 Msg :: Decrement = > * state - 1 } ) . assert_eq! ( * state . get () 0 ) ; dispatch ( Msg :: Increment ) ; assert_eq! ( * state . get () 1 ) ; dispatch ( Msg :: Decrement ) ; assert_eq! ( * state . get () 0 ) ; ` ` `