@@ -25,7 +25,38 @@ module Observable =
25
25
///
26
26
/// <returns>An Observable that propagates information from both sources.</returns>
27
27
///
28
- /// <example-tbd></example-tbd>
28
+ /// <example>
29
+ /// <code lang="fsharp">
30
+ /// open System.Reactive.Linq
31
+ /// open System
32
+ ///
33
+ /// let createTimer interval =
34
+ /// let timer = new Timers.Timer(interval)
35
+ /// timer.AutoReset <- true
36
+ /// timer.Enabled <- true
37
+ /// Observable.Create(fun observer -> timer.Elapsed.Subscribe(observer))
38
+ ///
39
+ /// let observableFirstTimer = createTimer 1000
40
+ /// let observableSecondTimer = createTimer 3000
41
+ ///
42
+ /// let result = Observable.merge observableFirstTimer observableSecondTimer
43
+ ///
44
+ /// result.Subscribe(fun output -> printfn $"Output - {output.SignalTime} ")
45
+ /// |> ignore
46
+ ///
47
+ /// Console.ReadLine() |> ignore
48
+ /// </code>
49
+ /// The sample will merge all events at a given interval and output it to the stream: <c>
50
+ /// Output - 2/5/2022 3:49:37 AM
51
+ /// Output - 2/5/2022 3:49:38 AM
52
+ /// Output - 2/5/2022 3:49:39 AM
53
+ /// Output - 2/5/2022 3:49:39 AM
54
+ /// Output - 2/5/2022 3:49:40 AM
55
+ /// Output - 2/5/2022 3:49:41 AM
56
+ /// Output - 2/5/2022 3:49:42 AM
57
+ /// Output - 2/5/2022 3:49:42 AM
58
+ /// </c>
59
+ /// </example>
29
60
[<CompiledName( " Merge" ) >]
30
61
val merge : source1 : IObservable < 'T > -> source2 : IObservable < 'T > -> IObservable < 'T >
31
62
@@ -38,7 +69,19 @@ module Observable =
38
69
///
39
70
/// <returns>An Observable of the type specified by <c>mapping</c>.</returns>
40
71
///
41
- /// <example-tbd></example-tbd>
72
+ /// <example>
73
+ /// <code lang="fsharp">
74
+ /// open System.Reactive.Linq
75
+ /// let numbers = seq { 1..5 }
76
+ /// let observableNumbers = Observable.ToObservable numbers
77
+ ///
78
+ /// let multiplyByTwo = fun number -> number * 2
79
+ /// let map = Observable.map multiplyByTwo observableNumbers
80
+ ///
81
+ /// map.Subscribe(fun x -> printf $"{x} ") |> ignore
82
+ /// </code>
83
+ /// The sample will output: <c>2 4 6 8 10</c>
84
+ /// </example>
42
85
[<CompiledName( " Map" ) >]
43
86
val map : mapping :( 'T -> 'U ) -> source : IObservable < 'T > -> IObservable < 'U >
44
87
@@ -54,7 +97,19 @@ module Observable =
54
97
///
55
98
/// <returns>An Observable that filters observations based on <c>filter</c>.</returns>
56
99
///
57
- /// <example-tbd></example-tbd>
100
+ /// <example>
101
+ /// <code lang="fsharp">
102
+ /// open System.Reactive.Linq
103
+ /// let numbers = seq { 1..5 }
104
+ /// let observableNumbers = Observable.ToObservable numbers
105
+ ///
106
+ /// let getEvenNumbers = fun number -> number % 2 = 0
107
+ /// let map = Observable.filter multiplyByTwo observableNumbers
108
+ ///
109
+ /// map.Subscribe(fun x -> printf $"{x} ") |> ignore
110
+ /// </code>
111
+ /// The sample will output: <c>2 4</c>
112
+ /// </example>
58
113
[<CompiledName( " Filter" ) >]
59
114
val filter : predicate :( 'T -> bool ) -> source : IObservable < 'T > -> IObservable < 'T >
60
115
@@ -73,7 +128,24 @@ module Observable =
73
128
/// <returns>A tuple of Observables. The first triggers when the predicate returns true, and
74
129
/// the second triggers when the predicate returns false.</returns>
75
130
///
76
- /// <example-tbd></example-tbd>
131
+ /// <example>
132
+ /// <code lang="fsharp">
133
+ /// open System.Reactive.Linq
134
+ /// let numbers = seq { 1..5 }
135
+ /// let observableNumbers = Observable.ToObservable numbers
136
+ ///
137
+ /// let isEvenNumber = fun number -> number % 2 = 0
138
+ /// let initialState = 2
139
+ ///
140
+ /// let leftPartition, rightPartition =
141
+ /// Observable.partition isEvenNumber observableNumbers
142
+ ///
143
+ /// leftPartition.Subscribe(fun x -> printfn $"Left partition: {x}") |> ignore
144
+ ///
145
+ /// rightPartition.Subscribe(fun x -> printfn $"Right partition: {x}") |> ignore
146
+ /// </code>
147
+ /// The sample evaluates to: <c>Left partition: 2, 4, Right partition: 1, 3, 5</c>
148
+ /// </example>
77
149
[<CompiledName( " Partition" ) >]
78
150
val partition : predicate :( 'T -> bool ) -> source : IObservable < 'T > -> ( IObservable < 'T > * IObservable < 'T >)
79
151
@@ -92,7 +164,36 @@ module Observable =
92
164
/// <returns>A tuple of Observables. The first triggers when <c>splitter</c> returns Choice1of2
93
165
/// and the second triggers when <c>splitter</c> returns Choice2of2.</returns>
94
166
///
95
- /// <example-tbd></example-tbd>
167
+ /// <example>
168
+ /// <code lang="fsharp">
169
+ /// open System.Reactive.Linq
170
+ /// let numbers = seq { 1..5 }
171
+ /// let observableNumbers = Observable.ToObservable numbers
172
+ ///
173
+ /// let getEvenNumbers number =
174
+ /// match number % 2 = 0 with
175
+ /// | true -> Choice1Of2 number
176
+ /// | false -> Choice2Of2 $"{number} is not an even number"
177
+ ///
178
+ /// let evenSplit, printOddNumbers = Observable.split getEvenNumbers observableNumbers
179
+ ///
180
+ /// let printOutput observable functionName =
181
+ /// use subscription =
182
+ /// Observable.subscribe
183
+ /// (fun output -> printfn $"{functionName} - Split output: {output}. Type: {output.GetType()}")
184
+ /// observable
185
+ ///
186
+ /// subscription
187
+ ///
188
+ /// printOutput evenSplit (nameof evenSplit) |> ignore
189
+ /// printOutput printOddNumbers (nameof printOddNumbers) |> ignore
190
+ /// </code>
191
+ /// The sample evaluates to: <c>evenSplit - Split output: 2. Type: System.Int32
192
+ /// evenSplit - Split output: 4. Type: System.Int32
193
+ /// printOddNumbers - Split output: 1 is not an even number. Type: System.String
194
+ /// printOddNumbers - Split output: 3 is not an even number. Type: System.String
195
+ /// printOddNumbers - Split output: 5 is not an even number. Type: System.String</c>
196
+ /// </example>
96
197
[<CompiledName( " Split" ) >]
97
198
val split : splitter :( 'T -> Choice < 'U1 , 'U2 >) -> source : IObservable < 'T > -> ( IObservable < 'U1 > * IObservable < 'U2 >)
98
199
@@ -107,7 +208,23 @@ module Observable =
107
208
///
108
209
/// <returns>An Observable that only propagates some of the observations from the source.</returns>
109
210
///
110
- /// <example-tbd></example-tbd>
211
+ /// <example>
212
+ /// <code lang="fsharp">
213
+ /// open System.Reactive.Linq
214
+ /// let numbers = seq { 1..5 }
215
+ /// let observableNumbers = Observable.ToObservable numbers
216
+ ///
217
+ /// let getOddNumbers number =
218
+ /// match number with
219
+ /// | _ when number % 2 = 0 -> None
220
+ /// | _ -> Some number
221
+ ///
222
+ /// let map = Observable.choose getOddNumbers observableNumbers
223
+ ///
224
+ /// map.Subscribe(fun x -> printf $"{x} ") |> ignore
225
+ /// </code>
226
+ /// The sample will output: <c>1 3 5</c>
227
+ /// </example>
111
228
[<CompiledName( " Choose" ) >]
112
229
val choose : chooser :( 'T -> 'U option ) -> source : IObservable < 'T > -> IObservable < 'U >
113
230
@@ -126,7 +243,20 @@ module Observable =
126
243
///
127
244
/// <returns>An Observable that triggers on the updated state values.</returns>
128
245
///
129
- /// <example-tbd></example-tbd>
246
+ /// <example>
247
+ /// <code lang="fsharp">
248
+ /// open System.Reactive.Linq
249
+ /// let numbers = seq { 1..5 }
250
+ /// let observableNumbers = Observable.ToObservable numbers
251
+ ///
252
+ /// let multiplyBy number = fun y -> number * y
253
+ /// let initialState = 2
254
+ /// let scan = Observable.scan multiplyBy initialState observableNumbers
255
+ ///
256
+ /// scan.Subscribe(fun x -> printf "%A " x) |> ignore
257
+ /// </code>
258
+ /// The sample evaluates to: <c>2 4 12 48 240</c>
259
+ /// </example>
130
260
[<CompiledName( " Scan" ) >]
131
261
val scan : collector :( 'U -> 'T -> 'U ) -> state : 'U -> source : IObservable < 'T > -> IObservable < 'U >
132
262
@@ -136,7 +266,16 @@ module Observable =
136
266
/// <param name="callback">The function to be called on each observation.</param>
137
267
/// <param name="source">The input Observable.</param>
138
268
///
139
- /// <example-tbd></example-tbd>
269
+ /// <example>
270
+ /// <code lang="fsharp">
271
+ /// open System.Reactive.Linq
272
+ /// let numbers = seq { 1..5 }
273
+ /// let observableNumbers = Observable.ToObservable numbers
274
+ /// let multiplyByTwo = fun number -> printf $"{number * 2} "
275
+ /// Observable.add multiplyByTwo observableNumbers
276
+ /// </code>
277
+ /// The sample evaluates to: <c>2 4 6 8 10</c>
278
+ /// </example>
140
279
[<CompiledName( " Add" ) >]
141
280
val add : callback :( 'T -> unit ) -> source : IObservable < 'T > -> unit
142
281
@@ -148,7 +287,18 @@ module Observable =
148
287
///
149
288
/// <returns>An object that will remove the callback if disposed.</returns>
150
289
///
151
- /// <example-tbd></example-tbd>
290
+ /// <example>
291
+ /// <code lang="fsharp">
292
+ /// open System.Reactive.Linq
293
+ /// let numbers = seq { 1..3 }
294
+ /// let observableNumbers = Observable.ToObservable numbers
295
+ /// let printOutput observable =
296
+ /// use subscription = Observable.subscribe (fun x -> printfn "%A" x) observable
297
+ /// subscription
298
+ /// printOutput observableNumbers |> ignore
299
+ /// </code>
300
+ /// The sample evaluates to: <c>1, 2, 3</c>
301
+ /// </example>
152
302
[<CompiledName( " Subscribe" ) >]
153
303
val subscribe : callback :( 'T -> unit ) -> source : IObservable < 'T > -> System.IDisposable
154
304
@@ -164,6 +314,18 @@ module Observable =
164
314
///
165
315
/// <returns>An Observable that triggers on successive pairs of observations from the input Observable.</returns>
166
316
///
167
- /// <example-tbd></example-tbd>
317
+ /// <example>
318
+ /// <code lang="fsharp">
319
+ /// /// open System.Reactive.Linq
320
+ /// let numbers = seq { 1..5 }
321
+ /// let observableNumbers = Observable.ToObservable numbers
322
+ ///
323
+ /// let pairWise = Observable.pairwise observableNumbers
324
+ ///
325
+ /// pairWise.Subscribe(fun pair -> printf $"{pair} ")
326
+ /// |> ignore
327
+ /// </code>
328
+ /// The sample evaluates to: <c>(1, 2), (2, 3), (3, 4), (4, 5)</c>
329
+ /// </example>
168
330
[<CompiledName( " Pairwise" ) >]
169
331
val pairwise : source : IObservable < 'T > -> IObservable < 'T * 'T >
0 commit comments