baconjs / bacon.js

Functional reactive programming library for TypeScript and JavaScript
https://baconjs.github.io
MIT License
6.47k stars 330 forks source link

fold issues with ES5 #669

Closed nogo10 closed 8 years ago

nogo10 commented 8 years ago

As shown on stackoverflow question ES6 arrow function " => " works fine with observable.fold(seed, f)

const stream = Bacon.sequentially(100, ["Hello", "world"])    
stream.log("stream")
const concatenated = stream.fold("", (a,b) => a + b)
concatenated.log("concatenated")

However in strict ES5 syntax:

var stream = Bacon.sequentially(100, ["Hello", "world"]);
stream.log("stream");
var concatenated = stream.fold("", function (a,b){ a + b});

it doesn't work results in 'undefined' value on console

raimohanska commented 8 years ago

You're missing a return statement :)

darrennolan commented 8 years ago

Because you've missed a return.

const concatenated = stream.fold("", (a,b) => a + b)

In es5 is actually

var concatenated = stream.fold("", function (a,b){ return a + b});

On Thu, 30 Jun 2016 4:42 pm Juha Paananen notifications@github.com wrote:

Closed #669 https://github.com/baconjs/bacon.js/issues/669.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/baconjs/bacon.js/issues/669#event-708739170, or mute the thread https://github.com/notifications/unsubscribe/ABEGa8wl9YP9IuipqDLCo4CHLlwbmKtsks5qQ2VMgaJpZM4JBwHK .

darrennolan commented 8 years ago

Sorry... Slow to the thread.

On Thu, 30 Jun 2016 5:39 pm Darren Nolan me@darrennolan.com wrote:

Because you've missed a return.

const concatenated = stream.fold("", (a,b) => a + b)

In es5 is actually

var concatenated = stream.fold("", function (a,b){ return a + b});

On Thu, 30 Jun 2016 4:42 pm Juha Paananen notifications@github.com wrote:

Closed #669 https://github.com/baconjs/bacon.js/issues/669.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/baconjs/bacon.js/issues/669#event-708739170, or mute the thread https://github.com/notifications/unsubscribe/ABEGa8wl9YP9IuipqDLCo4CHLlwbmKtsks5qQ2VMgaJpZM4JBwHK .

nogo10 commented 8 years ago

Ok -thanks- solved for me ..im the slow one