Skip to content

Commit

Permalink
Rename operation::chain to then
Browse files Browse the repository at this point in the history
... and make `focus_*` operations generic over
the output type.
  • Loading branch information
hecrj committed Aug 14, 2024
1 parent cfd2e7b commit 515772c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions core/src/widget/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ where

/// Chains the output of an [`Operation`] with the provided function to
/// build a new [`Operation`].
pub fn chain<A, B, O>(
pub fn then<A, B, O>(
operation: impl Operation<A> + 'static,
f: fn(A) -> O,
) -> impl Operation<B>
Expand Down Expand Up @@ -361,7 +361,7 @@ where
Outcome::Chain(Box::new((self.next)(value)))
}
Outcome::Chain(operation) => {
Outcome::Chain(Box::new(chain(operation, self.next)))
Outcome::Chain(Box::new(then(operation, self.next)))
}
}
}
Expand Down
14 changes: 10 additions & 4 deletions core/src/widget/operation/focusable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ pub fn count() -> impl Operation<Count> {
/// Produces an [`Operation`] that searches for the current focused widget, and
/// - if found, focuses the previous focusable widget.
/// - if not found, focuses the last focusable widget.
pub fn focus_previous() -> impl Operation {
pub fn focus_previous<T>() -> impl Operation<T>
where
T: Send + 'static,
{
struct FocusPrevious {
count: Count,
current: usize,
Expand Down Expand Up @@ -128,13 +131,16 @@ pub fn focus_previous() -> impl Operation {
}
}

operation::chain(count(), |count| FocusPrevious { count, current: 0 })
operation::then(count(), |count| FocusPrevious { count, current: 0 })
}

/// Produces an [`Operation`] that searches for the current focused widget, and
/// - if found, focuses the next focusable widget.
/// - if not found, focuses the first focusable widget.
pub fn focus_next() -> impl Operation {
pub fn focus_next<T>() -> impl Operation<T>
where
T: Send + 'static,
{
struct FocusNext {
count: Count,
current: usize,
Expand Down Expand Up @@ -162,7 +168,7 @@ pub fn focus_next() -> impl Operation {
}
}

operation::chain(count(), |count| FocusNext { count, current: 0 })
operation::then(count(), |count| FocusNext { count, current: 0 })
}

/// Produces an [`Operation`] that searches for the current focused widget
Expand Down

0 comments on commit 515772c

Please sign in to comment.