reactive-programming

How to use Reactive Extensions to parse a stream of characters from a serial port?

早过忘川 提交于 2019-12-05 05:43:08
I need to parse a stream of serial data coming from a test instrument, and this seems to be an excellent application for Reactive Extensions. The protocol is very simple...each "packet" is a single letter followed by numeric digits. The number of numeric digits is fixed for each packet type, but can vary between packet types. e.g. ...A1234B123456C12... I am trying to break this up into an Observable of Strings, e.g. "A1234" "B123456" "C12" ... Thought this would be simple, but don't see the obvious way to approach this (I have some experience with LINQ, but am new to Rx). Here's the code I

reactive-banana throttling events

感情迁移 提交于 2019-12-05 05:08:49
I would like to implement a certain type of throttling of events in reactive-banana. It should work such that an event is not let through if arrives at less then delta seconds from the last event that passed through. If it is not let through then it is stored and is fired after delta seconds from the last fired event. Below is a program that implements this for lists of time stamped numbers. Would it be possible to translate this to reactive-banana ? Also, in reactive-banana how do I fire an event x seconds after some other event comes in ? module Main where import Data.List -- 1 second

Should rxjs subjects be public in the class?

不羁的心 提交于 2019-12-05 04:22:46
Let's say I have two classes, where you can observe over some observables. First example, with public subject: class EventsPub { public readonly onEnd = new Subject<void>(); } Second example, with private subject and registering method: class EventsPriv { private readonly endEvent = new Subject<void>(); public onEnd(cb: () => void): Subscription { return this.endEvent.subscribe(cb); } } The first example is somehow unsafe because anyone can call eventsPub.endEvent.next() from outside the class and introduce side effects, however, comparing to example 2 It allows for pipes, which is a big plus

RxJava/RxAndroid - handle multiple EditText changes

此生再无相见时 提交于 2019-12-05 03:31:10
I have 3 EditText fields and I have created 3 observables for these fields. Observable<CharSequence> o1 = RxTextView.textChanges(field1); Observable<CharSequence> o2 = RxTextView.textChanges(field2); Observable<CharSequence> o3 = RxTextView.textChanges(field3); I want to enable a button when all these three fields has some value in it. user can enter values in any order in the fields. How can i do that? EDIT I used zip to achieve that. Observable<CharSequence> o1 = RxTextView.textChanges(field1); Observable<CharSequence> o2 = RxTextView.textChanges(field2); Observable<CharSequence> o3 =

Enabling an UIButton using Reactive Cocoa RACSignal

南楼画角 提交于 2019-12-05 02:48:38
问题 I have a UIButton added to a view. My view also has three text box viz. username , password and confirmPassword . Based on the legitimate content of these text box, I need to enable my signUp button. Here is my code snippet :- UIButton *signUp = [[UIButton alloc]initWithFrame:CGRectMake(10, 100, 50, 20)]; signUp.backgroundColor = [UIColor greenColor]; signUp.enabled = NO ; [self.view addSubview:signUp]; RACSignal *formValid = [RACSignal combineLatest:@[ username.rac_textSignal, password.rac

Chaining RxJs Observables in Angular 2

孤者浪人 提交于 2019-12-05 02:29:35
问题 I've got a TypeScript function in my Angular 2 app that returns an Observable, to push web API data back to the consumer, something like this: public getApiData(): Observable { let readySource = Observable.from('no', 'no', 'ready'); let dataSource = http.get('api/getData'); // ... magic here return chainedObservable; } However, rather than returning the http.get Observable as normal, I need to chain this HTTP call to another readySource Observable that indicates whether the API is ready to

Rx - Divide stream into segments (lists) by condition

会有一股神秘感。 提交于 2019-12-05 02:27:24
I have an RX producer that creates a stream of strings like so (simplified version of the real stream): A1 A2 A3 B1 B2 C1 C2 C3 C4 C5 C6.... The stream is endless, but ordered. So after the strings that start with A run out, B starts. When B runs out, C starts... when Z run out, we move to AA1 etc. There's an unknown number of A 's, B 's etc, but it's typically 10-30 instances per letter. I'm looking for a way to divide this stream into blocks of all A's: A1 A2 A3 , all B's: B1 B2 , all C's: C1 C2 C3 C4 C5 C6 etc. Each block can be either an observable (which I'll turn into a list) or simply a

Filter list of objects in RxJava

放肆的年华 提交于 2019-12-05 01:23:26
I am trying to filter the list on the basis of it's property. For example, Sensors class has a property isActive and I want to get all the objects with isActive as true but I am unable to do it. I tried different ways but I didn't find the solution. Can someone help me to do it? Here is my code: mCompositeDisposable.add( fcService.getStationList() .subscribeOn(Schedulers.io()) .flatMap( stations -> { return fcService.getSensorList(stations.get(0).getName().getOriginal()); }) .subscribe(this::handleSensors, this::handleError) ); First, you need to emit each item from the List individually. That

RxJava/Android: Combine result of two dependent Observables

余生颓废 提交于 2019-12-05 01:09:42
I have two Observables . Observable<A> getAObservable() Returns Observable of A Observable<B> getBObservable(A) Returns Observable of 'B'. Here Observable<A> should execute before Observable<B> so that it can pass its result A to getBObservable() method. Now once Observable<B> completes I need to combine the result of these observable and Observable<AB> should returns. Options Tried: Take Observable<A> and apply flatMap on it so that it transform result in B . Now at this point I am not having access to A data. Hence I can't return Observable I can use zip so that once I get the result of both

Functional reactive programming — is Fay expressive enough? [closed]

与世无争的帅哥 提交于 2019-12-05 00:02:42
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . So I'm doing a fairly involved javascript/html client with lots of ajax calls and other involvements of callback-ism. I'm entertaining the thought of using Fay for this purpose. I'm aware of Elm. Tried it and liked the FRP elements. Now