baconjs / bacon.js

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

Meaningful toString implementation #265

Closed raimohanska closed 10 years ago

raimohanska commented 10 years ago

How about a toString() function that would return something like this:

combineAsArray([constant(a),constant(b)])

or

take(merge(later(1, "lol"), later(2, "wat")), 1)

A quick implementation exists at 30ae4aa1ef0a64bc42fbe61cb6bb736a4f1bbe98. And when I say quick I mean that all tests for toString are missing at the moment.

raimohanska commented 10 years ago

In fd95c4ba00218292f53e17948db61be404a62364, I've implementated and tested a lot of toString implementations... Still some combinators left.

My feeling is that this might be worth the effort :)

raimohanska commented 10 years ago

Most of the work is already done in the branch feature/dependency-graph-dispatch.

Todo: specs for the rest of the combinators.

raimohanska commented 10 years ago

I'm planning to include this in release 0.7.0. Help is appreciated!

raimohanska commented 10 years ago

Whoa. Just squeezed the toString implementations in.

So, this stuff is ready for release, and resides currently in the feature/dependency-graph-dispatch branch.

raimohanska commented 10 years ago

This is actually a comeback of #107.

@dnalot @hden @RoboTeddy any comments? Should we include .inspect too?

raimohanska commented 10 years ago

Hmm.. When running in CoffeeScript, the new toString doesn't seem to work:

var Bacon=require("./dist/Bacon")
coffee> Bacon._.toString({a:"b"})
'[object Object]'

This is weird, as the tests pass quite well and they are done in coffee too.

hden commented 10 years ago

It seem to be only happing in the REPL. Perhaps its a compiler issue?

# test.coffee
'use strict'
Bacon = require "./dist/Bacon"
console.log Bacon._.toString({a:"b"})
# shell
$ coffee test.coffee 
{a:b}
# REPL
> Bacon = require "./dist/Bacon"
...
> console.log Bacon._.toString({a:"b"})
[object Object]
philipnilsson commented 10 years ago

Yeah, I think it's Node.js, see e.g. http://stackoverflow.com/questions/7428235/how-to-print-json-object-content-in-node-js How come it's an object, not a string?

On Mon, Nov 4, 2013 at 2:10 AM, Hao-kang Den notifications@github.comwrote:

It seem to be only happing in the REPL. Perhaps its a compiler issue?

test.coffee'use strict'Bacon = require "./dist/Bacon"console.log Bacon._.toString({a:"b"})

shell

$ coffee test.coffee {a:b}

REPL

Bacon = require "./dist/Bacon" ... console.log Bacon._.toString({a:"b"}) [object Object]

— Reply to this email directly or view it on GitHubhttps://github.com/baconjs/bacon.js/issues/265#issuecomment-27659933 .

hden commented 10 years ago

It seems that this problem is fixed in the current master of coffee-script. Ready to close this issue?

raimohanska commented 10 years ago

The implementation is now in feature/0.7 and will be included in the 0.7.0 release.

raimohanska commented 10 years ago

One more thing: should we support .inspect() also?

I'm thinking about supporting toString/inspect for the following:

Should have tests for all of the included objects/classes.

raimohanska commented 10 years ago

Added a name method as @rassie suggested in #273.

Also implemented inspect for nice node output.

Now you can

> B.once("1").name("one")
one
> B.once(1).name("stuff").take(1)
stuff.take(1)

I'm done with this one!