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

feat: Add the Tail higher-order stream #69

Merged
merged 4 commits into from
Jan 28, 2025

Conversation

Hywan
Copy link
Collaborator

@Hywan Hywan commented Jan 15, 2025

This patch adds the Tail higher-order stream. Similarly to Head,
it computes a limited view of the underlying ObservableVector's
items, however the view starts from the end —instead of the start— of
the ObservableVector.

use eyeball_im::{ObservableVector, VectorDiff};
use eyeball_im_util::vector::VectorObserverExt;
use imbl::vector;
use stream_assert::{assert_closed, assert_next_eq, assert_pending};

// Our vector.
let mut ob = ObservableVector::<char>::new();
let (values, mut sub) = ob.subscribe().tail(3);

assert!(values.is_empty());
assert_pending!(sub);

// Append multiple values.
ob.append(vector!['a', 'b', 'c', 'd']);
// We get a `VectorDiff::Append` with the latest 3 values!
assert_next_eq!(sub, VectorDiff::Append { values: vector!['b', 'c', 'd'] });

// Let's recap what we have. `ob` is our `ObservableVector`,
// `sub` is the “limited view” of `ob`:
// | `ob`  | a b c d |
// | `sub` |   b c d |

// Append multiple other values.
ob.append(vector!['e', 'f']);
// We get three `VectorDiff`s!
assert_next_eq!(sub, VectorDiff::PopFront);
assert_next_eq!(sub, VectorDiff::PopFront);
assert_next_eq!(sub, VectorDiff::Append { values: vector!['e', 'f'] });

// Let's recap what we have:
// | `ob`  | a b c d e f |
// | `sub` |       d e f |
//             ^ ^   ^^^
//             | |   |
//             | |   added with `VectorDiff::Append { .. }`
//             | removed with `VectorDiff::PopFront`
//             removed with `VectorDiff::PopFront`

assert_pending!(sub);
drop(ob);
assert_closed!(sub);

@Hywan Hywan force-pushed the feat-im-util-rlimit branch 4 times, most recently from 181ff00 to 499281e Compare January 17, 2025 10:40
@Hywan Hywan marked this pull request as ready for review January 17, 2025 10:46
@Hywan Hywan requested a review from jplatte January 17, 2025 10:46
@Hywan Hywan force-pushed the feat-im-util-rlimit branch from 4d6177d to 69f4f52 Compare January 17, 2025 11:10
Hywan added a commit to Hywan/eyeball that referenced this pull request Jan 20, 2025
This patch renames the higher-order stream `Limit` to `Head`. It is
a reaction to the upcoming jplatte#69
where I've initially proposed the name `RLimit`. After a short thinking,
I believe renaming `Limit` to `Head` and `RLimit` to `Tail` would be
better names.

This patch renames `Limit` to `Head`.
@Hywan Hywan mentioned this pull request Jan 20, 2025
@Hywan Hywan force-pushed the feat-im-util-rlimit branch from 69f4f52 to e5d9883 Compare January 20, 2025 13:35
@Hywan
Copy link
Collaborator Author

Hywan commented Jan 20, 2025

Rebased on top of #70, and renamed RLimit to Tail

@Hywan Hywan changed the title feat: Add the RLimit higher-order stream feat: Add the Tail higher-order stream Jan 20, 2025
Hywan added a commit that referenced this pull request Jan 22, 2025
This patch renames the higher-order stream `Limit` to `Head`. It is
a reaction to the upcoming #69
where I've initially proposed the name `RLimit`. After a short thinking,
I believe renaming `Limit` to `Head` and `RLimit` to `Tail` would be
better names.

This patch renames `Limit` to `Head`.
@Hywan Hywan force-pushed the feat-im-util-rlimit branch from ba6437a to 77d6e68 Compare January 22, 2025 18:47
Hywan added 4 commits January 22, 2025 19:52
This patch adds the `Tail` higher-order stream. Similarly to `Head`,
it computes a limited view of the underlying `ObservableVector`'s
items, however the view starts from the end —instead of the start— of
the `ObservableVector`
@Hywan Hywan force-pushed the feat-im-util-rlimit branch from 77d6e68 to fd06b17 Compare January 22, 2025 18:52
@Hywan
Copy link
Collaborator Author

Hywan commented Jan 22, 2025

Rebased on top of main (which now includes #70).

@jplatte jplatte merged commit 80579c5 into jplatte:main Jan 28, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants