-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathWordBreaking.cs
31 lines (23 loc) · 986 Bytes
/
WordBreaking.cs
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
using System.Reactive.Linq;
namespace RxQueryOperators;
public static class WordBreaking
{
public static void BreakTextWithWindows()
{
var keySource = new KeyWatcher();
IObservable<IObservable<char>> wordWindows = keySource.Window(
() => keySource.FirstAsync(char.IsWhiteSpace));
IObservable<string> words = from wordWindow in wordWindows
from chars in wordWindow.ToArray()
select new string(chars).Trim();
words.Subscribe(word => Console.WriteLine("Word: " + word));
}
public static void BreakTextWithBuffers()
{
var keySource = new KeyWatcher();
IObservable<IList<char>> wordWindows = keySource.Buffer(
() => keySource.FirstAsync(char.IsWhiteSpace));
IObservable<string> words = from wordWindow in wordWindows
select new string(wordWindow.ToArray()).Trim();
}
}