Skip to content

Commit 1d4f6eb

Browse files
authored
Merge pull request #3 from Asterless/doc
Add method description comments consistent with `core` and perform partial translation
2 parents 6ee76e6 + 3df1648 commit 1d4f6eb

File tree

4 files changed

+1122
-374
lines changed

4 files changed

+1122
-374
lines changed

src/examples.mbt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,37 @@
11
/// ReactiveX for MoonBit - 使用示例
22
/// 展示基本的Observable创建和订阅功能
33
4+
///|
45
/// 基础使用示例
56
pub fn example_basic_usage() -> Unit {
67
println("=== 基础使用示例 ===")
7-
8+
89
// 1. 创建一个简单的Observable
910
let simple_obs = of(42)
1011
let _ = simple_obs.subscribe_next(fn(value) {
1112
println("接收到值: {value}")
1213
})
13-
14+
1415
// 2. 创建数组Observable
1516
let array_obs = from_array([1, 2, 3])
1617
let _ = array_obs.subscribe_next(fn(value) {
1718
println("数组元素: {value}")
1819
})
19-
2020
println("=== 示例完成 ===")
2121
}
2222

23+
///|
2324
/// 操作符链示例
2425
pub fn example_operator_chain() -> Unit {
2526
println("=== 操作符链示例 ===")
26-
27+
2728
// 简单的操作符链
2829
let processed = from_array([1, 2, 3, 4, 5])
29-
|> filter(fn(x) { x % 2 == 1 }) // 只保留奇数
30-
|> map(fn(x) { x * x }) // 平方
31-
|> take(3) // 取前3个
32-
30+
|> filter(fn(x) { x % 2 == 1 }) // 只保留奇数
31+
|> map(fn(x) { x * x }) // 平方
32+
|> take(3) // 取前3个
3333
let _ = processed.subscribe_next(fn(value) {
3434
println("处理后的值: {value}")
3535
})
36-
3736
println("=== 示例完成 ===")
38-
}
37+
}

src/pkg.generated.mbti

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Generated using `moon info`, DON'T EDIT IT
2+
package "CGaaaaaa/reactivex/src"
3+
4+
// Values
5+
fn[T] catch_error(Observable[T], (RxError) -> Observable[T]) -> Observable[T]
6+
7+
fn[T, U, V] combine_latest(Observable[T], Observable[U], (T, U) -> V) -> Observable[V]
8+
9+
fn[T] concat(Array[Observable[T]]) -> Observable[T]
10+
11+
fn[T] debounce(Observable[T], Int) -> Observable[T]
12+
13+
fn[T : Eq] distinct(Observable[T]) -> Observable[T]
14+
15+
fn[T] empty() -> Observable[T]
16+
17+
fn[T] error(String) -> Observable[T]
18+
19+
fn[T] error_with_type(RxError) -> Observable[T]
20+
21+
fn example_basic_usage() -> Unit
22+
23+
fn example_operator_chain() -> Unit
24+
25+
fn[T] filter(Observable[T], (T) -> Bool) -> Observable[T]
26+
27+
fn[T, U] flat_map(Observable[T], (T) -> Observable[U]) -> Observable[U]
28+
29+
fn[T] from_array(Array[T]) -> Observable[T]
30+
31+
fn[T, U] map(Observable[T], (T) -> U) -> Observable[U]
32+
33+
fn[T] merge(Array[Observable[T]]) -> Observable[T]
34+
35+
fn[T] never() -> Observable[T]
36+
37+
fn[T] new_observable((Observer[T]) -> BasicSubscription) -> Observable[T]
38+
39+
fn[T] new_observer((T) -> Unit, (RxError) -> Unit, () -> Unit) -> Observer[T]
40+
41+
fn[T] new_simple_observer((T) -> Unit, (String) -> Unit, () -> Unit) -> Observer[T]
42+
43+
fn new_subscription() -> BasicSubscription
44+
45+
fn[T] of(T) -> Observable[T]
46+
47+
fn[T, U] reduce(Observable[T], U, (U, T) -> U) -> Observable[U]
48+
49+
fn[T] retry(Observable[T], Int) -> Observable[T]
50+
51+
fn[T, U] scan(Observable[T], U, (U, T) -> U) -> Observable[U]
52+
53+
fn[T] skip(Observable[T], Int) -> Observable[T]
54+
55+
fn[T] start_with(Observable[T], T) -> Observable[T]
56+
57+
fn[T, U] switch_map(Observable[T], (T) -> Observable[U]) -> Observable[U]
58+
59+
fn[T] take(Observable[T], Int) -> Observable[T]
60+
61+
fn[T] tap(Observable[T], (T) -> Unit) -> Observable[T]
62+
63+
fn[T, U, V] zip(Observable[T], Observable[U], (T, U) -> V) -> Observable[V]
64+
65+
// Errors
66+
67+
// Types and methods
68+
pub struct BasicSubscription {
69+
mut subscribed : Bool
70+
}
71+
fn BasicSubscription::is_subscribed(Self) -> Bool
72+
fn BasicSubscription::unsubscribe(Self) -> Unit
73+
74+
pub struct Observable[T] {
75+
subscribe_fn : (Observer[T]) -> BasicSubscription
76+
}
77+
fn[T] Observable::subscribe(Self[T], Observer[T]) -> BasicSubscription
78+
fn[T] Observable::subscribe_next(Self[T], (T) -> Unit) -> BasicSubscription
79+
80+
pub struct Observer[T] {
81+
on_next : (T) -> Unit
82+
on_error : (RxError) -> Unit
83+
on_complete : () -> Unit
84+
}
85+
86+
pub enum RxError {
87+
RuntimeError(String)
88+
OperatorError(String)
89+
SubscriptionError(String)
90+
TimeoutError(String)
91+
}
92+
93+
// Type aliases
94+
95+
// Traits
96+

0 commit comments

Comments
 (0)