Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(hydro_lang)!: rename singleton_first_tick to optional_first_tick and add example of doctest #1659

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hydro_lang/src/location/tick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl<'a, L: Location<'a>> Tick<L> {
}
}

pub fn singleton_first_tick<T: Clone>(
pub fn optional_first_tick<T: Clone>(
&self,
e: impl QuotedWithContext<'a, T, Tick<L>>,
) -> Optional<T, Self, Bounded>
Expand Down
18 changes: 18 additions & 0 deletions hydro_lang/src/optional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,24 @@ impl<'a, T: Clone, L: Location<'a>, B> Clone for Optional<T, L, B> {
}

impl<'a, T, L: Location<'a>, B> Optional<T, L, B> {
/// Transforms the optional value by applying a function `f` to it,
/// continuously as the input is updated.
///
/// Whenever the optional is empty, the output optional is also empty.
///
/// # Example
/// ```rust
/// # use hydro_lang::*;
/// # use dfir_rs::futures::StreamExt;
/// # tokio_test::block_on(test_util::stream_transform_test(|process| {
/// let tick = process.tick();
/// let optional = tick.optional_first_tick(q!(1));
/// optional.map(q!(|v| v + 1)).all_ticks().drop_timestamp()
/// # }, |mut stream| async move {
/// // 2
/// # assert_eq!(stream.next().await.unwrap(), 2);
/// # }));
/// ```
pub fn map<U, F: Fn(T) -> U + 'a>(self, f: impl IntoQuotedMut<'a, F, L>) -> Optional<U, L, B> {
let f = f.splice_fn1_ctx(&self.location).into();
Optional::new(
Expand Down
2 changes: 1 addition & 1 deletion hydro_test/src/cluster/bench_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn bench_client<'a>(
// r_to_clients_payload_applied.clone().inspect(q!(|payload: &(u32, ReplicaPayload)| println!("Client received payload: {:?}", payload)));

// Set up an initial set of payloads on the first tick
let start_this_tick = client_tick.singleton_first_tick(q!(()));
let start_this_tick = client_tick.optional_first_tick(q!(()));

let c_new_payloads_on_start = start_this_tick.clone().flat_map_ordered(q!(move |_| (0
..num_clients_per_node)
Expand Down
Loading