1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2025 Umberto Gotti <umberto.gotti@umbertogotti.dev>
// Licensed under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
//! Take-items operator - limits stream to first n items.
//!
//! The `take_items` operator allows any stream of `StreamItem<T>` to be limited to
//! the first n items.
//!
//! # Arguments
//!
//! * `n` - The maximum number of items to emit.
//!
//! # Returns
//!
//! A new stream that emits at most `n` items from the source stream.
//!
//! # Error Handling
//!
//! **Important:** Errors count as items for the purpose of the limit.
//! If you want to take 3 values and the stream emits `[Value, Error, Value, Value, Value]`,
//! only the first 3 items will be emitted: `[Value, Error, Value]`.
//!
//! Errors are propagated unchanged. Use `.on_error()` before `take_items()` if you want
//! to filter errors before counting.
//!
//! # Examples
//!
//! ```rust
//! use fluxion_stream::{TakeItemsExt, IntoFluxionStream};
//! use fluxion_test_utils::Sequenced;
//! use futures::StreamExt;
//!
//! # async fn example() {
//! let (tx, rx) = async_channel::unbounded();
//! let stream = rx.into_fluxion_stream();
//!
//! let mut first_two = stream.take_items(2);
//!
//! tx.try_send(Sequenced::new(1)).unwrap();
//! tx.try_send(Sequenced::new(2)).unwrap();
//! tx.try_send(Sequenced::new(3)).unwrap();
//! drop(tx);
//!
//! assert_eq!(first_two.next().await.unwrap().unwrap().into_inner(), 1);
//! assert_eq!(first_two.next().await.unwrap().unwrap().into_inner(), 2);
//! assert!(first_two.next().await.is_none());
//! # }
//! ```
//!
//! # See Also
//!
//! - [`SkipItemsExt::skip_items`](crate::SkipItemsExt::skip_items) - Skip first n items
//! - [`StartWithExt::start_with`](crate::StartWithExt::start_with) - Prepend items
pub use TakeItemsExt;
pub use TakeItemsExt;