Menu
  • HOME
  • TAGS

Why does a Bacon.combineAsArray Stream of 'keyup' events immediately end?

javascript,jquery,frp,bacon.js

Add a .get() or .toArray() so that you pass a real array to Bacon, not a jQuery object (that is returned by map). Bacon will mistake that for a constant (since it's not instanceof Array), and return an ended, constant property. var phraseCorrect = Bacon.combineAsArray($('.keyphrase-list input') .map(mapFromInputToStream) .get()); ...

Kefir.js - How to stream events from a callback function?

javascript,frp

You can use general wrapper stream var leftKeys = Kefir.stream(function(emitter){ Mousetrap.bind('left', function(e) { emitter.emit(e); console.log(e); }); return function(){ // unbind }; }); http://jsfiddle.net/be9200kh/1/...

Breaking a cycle in FRP snake in Bacon.js

javascript,frp,bacon.js

Once it has been constructed, Bacon can usually handle a cyclic dependency between Observables. It is constructing them that's a bit tricky. In a language like Javascript, to create a structure with a cycle in it (i.e. a doubly-linked list), you need a mutable variable. For regular objects you use...

Haskell Netwire: wires of wires

haskell,frp,netwire

The problem is that the wires generated from the events are not persistent. A given value of type Wire s e m a b is actually an instance in time of a function that produces a value of type b from a value of type a. Since Haskell uses immutable...

Observing sub-class properties in Swift (Reactive Cocoa)

swift,reactive-cocoa,frp

The observation is backwards. Try: userLocation.rac_valuesForKeyPath("newLocation", observer: self).subscribeNextAs { (value) -> () in println("New location received!") } ...

How do I get keepWhen behaviour in Elm 0.15?

functional-programming,frp,elm

Answer: import it from a utility package The easiest way is to use Signal.Extra.keepWhen from the signal-extra package. (full disclosure: I'm the author) Important implementation detail Notice that the implementation isn't completely trivial. This is the implementation in the package (the Signal module is imported unqualified): keepWhen : Signal Bool...

How do I merge signals in Helm?

haskell,frp,elm

I think the best way would be finding out how Helm's Signals are implemented in terms of Elerea's stuff, and implementing merge in those more primitive terms. I'm afraid I can't help you there, because I don't know Helm well and I don't know Elerea at all. I can help...

Dealing with the current time in reactive-banana

haskell,frp,reactive-banana

Given your example use case, I think you should be fine if you stay away from fromPoll. To explain why, a few clarifications are needed. (Note: in what follows, "stream" refers to an Event t a, and "occurrence" to one of the firings which compose them.) However, polling Behaviours with...

Testing in reactive-banana

haskell,reactive-programming,frp,reactive-banana

When you say "unit test," I'm imagining something like QuickCheck, where you inject a number of inputs into the network and examine the outputs. To do such a thing, we'd need a function along the lines of: evalNetwork :: Network a b -> [a] -> IO [b] Near the end...

Put in / remove from the basket using Rx

reactive-programming,rx-java,frp,rxjs,rx-android

Take a look at withLatestFrom. It will only propagate when the primary source emits while combining the latest values from the other sources. ViewObservable.clicks(mPurchaseButton) .withLatestFrom(inBasketStream, (dontCare, inBasket) -> inBasket) .subscribe(/*do your update*/); ...

how to solve type issues with Moment t in reactive-banana?

haskell,reactive-programming,frp,reactive-banana

You need to given an explicit type signature for your startRBMidi function, because it has a rank-2 type: startRBMidi :: (forall t. Event t MIDIMessage -> Moment t ()) -> IO () This is similar to the type of the compile function. Essentially, this says that the argument function f...

Chaining promises with RxJS

javascript,observable,frp,rxjs

If I understood what you are trying to do - you need to create two deferred observables from functions that return promises and concat them: var shouldFail = false; function action1() { return new Promise(function (resolve, reject) { console.log('start action1'); if (shouldFail) { reject('reason'); } resolve(true); }); } function action2()...

ReactiveCocoa 3: Map signal to value (Swift)

ios,swift,reactive-cocoa,frp

It turned out my Api.get() function should return a SignalProducer instead of a Signal. With this adjustment I ended up with a solution like this: let keywordToJson: SignalProducer<String, NSError> -> SignalProducer<JSON, NSError> = flatMap(.Concat) { keyword in Api().get("search/\(keyword)" } searchText.producer |> mapError { _ in NSError() } |> keywordToJson |>...

Dynamic Elements based on Behaviour in threepenny-gui

haskell,frp,threepenny-gui

(Author here) Note that UI Element represents an action that, when executed, may create a new Element. You will have to execute the action to do the latter. Unfortunately, there is currently no way to do that completely within the FRP style, you will have to resort to the onChanges...

Bacon Bus weird behaviour with end of stream event

javascript,reactive-programming,frp,bacon.js

That would be because the Bus doesn't end: you can still push more events to the Bus. The only case when a Bus ends is when you call the end() method on the Bus.

The ability to create Doc element of hypertext in Websharper.UI.Next

web,f#,frp,websharper

Already answered this on https://github.com/intellifactory/websharper.ui.next/issues/22 but copying my answer here: If all you want is to create a UI.Next Doc from static html you can do the following: let htmlElem = JQuery.JQuery.Of("<div>hello</div>").Get(0) let doc = Doc.Static (htmlElem :?> _) This is not very nice but should work and I don't...

Native JS in node.js and FRP(bacon.js)

javascript,node.js,frp,bacon.js

Baconjs has generated pure js library: https://github.com/baconjs/bacon.js/tree/master/dist For examples check this example application - todoApp....

How is FRP handled in terms of memory?

haskell,memory-management,frp

The fact that this can work for simple cases should not be much of a surprise: we already comfortably use infinite data structures in Haskell thanks to laziness and garbage collection. As long as your final result does not depend on having all your values at once, they can be...

How to make use of scan() more clear

javascript,reactive-programming,frp,bacon.js

If you read what I wrote previously, ignore. it. :) This situation is exactly what flatMap is for: streams that create streams. Use flatMap. // Helper function var neg = function (a) { return !a; }; // Fake of initialization stream. End after one element // Note the use of...

Never running stream Bacon.js. Callback never calls

node.js,reactive-programming,frp,bacon.js

You don't see the value as there are no subscribers in the stream. Bacon only starts listening to events from the source when first subscriber is added (and stops listening to events when the last subscriber is removed). You can fix this by adding a subscriber, e.g. var tickStream =...

recursive update a “Behaviour” in Sodium yields 'thread blocked …'

haskell,frp,sodiumfrp

Your recursive let from RecursiveDo is in the IO monad. The Reactive monad also has a MonadFix instance. You can define b completely within Reactive and then use a sync around this to execute the entire definition as a transaction. main = do (e, t) <- sync newEvent b <-...

Ignore past values from FRP event stream

javascript,frp,bacon.js

Looks like you're abusing Bacon.onValues, whose purpose is to create a new stream. If you want to wait for the start of the module, just register the listener only when it has started: sTick = Bacon.fromEventTarget emitter, 'tick' module.onStart -> # when module has been started sTick.onValue -> # Do...

Sequential conditions in Bacon/FRP

frp,bacon.js

Assuming you want S3 to output some function of the values of S1 and S2, here is one way: s3 = s1.flatMapLatest(function(s1Val) { return s2.take(1).map(function(s2Val) { return someFunc(s1Val, s2Val); }); }); That's a general solution, but there are two simplifications: If you just want S1's values in S3: s3 =...

How would I cancel a click event if it was following a drag event using Bacon.js?

javascript,reactive-programming,frp,bacon.js

The solution is to create a property using stream.awaiting() that can be used to filter out the click after dragging. var btn = $('#btn'); var mouseUps = btn.asEventStream('mouseup'); var mouseDowns = btn.asEventStream('mousedown'); var mouseMoves = btn.asEventStream('mousemove'); var drags = mouseDowns.flatMapLatest(function () { return mouseMoves.takeUntil(mouseUps); }); var clicks = btn.asEventStream('click'); var...

Task mixed in a signal

signals,frp,elm

Answer Tasks in Elm 0.15 are executed by sending them through a port. That means that your Task or Signal Task needs to be available at the top-level in the Main module, because that's the only place where you can declare a port. This means that you cannot simply send...