Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map shouldn't accept a value. Move that to value() #404

Closed
buchanae opened this issue Nov 24, 2015 · 9 comments
Closed

Map shouldn't accept a value. Move that to value() #404

buchanae opened this issue Nov 24, 2015 · 9 comments
Labels
Milestone

Comments

@buchanae
Copy link

I can see the idea behind allowing map to accept a value, and it's probably useful, but it's also confusing and breaks a long standing contract (the signature of a map function). The reason I'm here is because of this:

class Index {
  lookupValue { ...pretend code... }

  getValueAtTime(time) {
    return this.lookupValue(time);
  }
}

var index = new Index();
var stream = someOtherStream.map(index.getValueForTime);

This returns a stream of undefined.
How long did it take you to see the error there? Took me hours.

Highland.value(val) (there's maybe a better name) would clear this up and save me some sanity.

@vqvu vqvu added the 3.x label Nov 24, 2015
@svozza
Copy link
Collaborator

svozza commented Nov 24, 2015

I didn't even realise this was a feature of our map. Big +1 on this.

@vqvu
Copy link
Collaborator

vqvu commented Nov 24, 2015

I agree that it's confusing. I don't even see it being all that useful (as evidenced by the fact that I didn't even know this behavior existed!). Unfortunately, it's documented, and we can't break backwards compatibility in 2.x.

Highland contributors, what are your thoughts on changing this behavior in 3.0? map is ubiquitous enough that nobody would bother reading the docs for it (imo) or expect that it can take non-functions as arguments. Splitting the behavior into a separate value/constantMap seems better to me.

@LewisJEllis
Copy link
Collaborator

Definite +1 for 3.0.

@vqvu vqvu added this to the 3.0.0 milestone Nov 24, 2015
@jeromew
Copy link
Collaborator

jeromew commented Nov 24, 2015

I started using it last week after seeing it in the doc so I suppose that other people use it to and it is indeed a breaking change.

+1 though for 3.x. We have some duck typing also in the constructor but I agree that for map it can be a debugging hell.

Do we have a solution for deprecation warning ?

@svozza
Copy link
Collaborator

svozza commented Nov 24, 2015

I guess a name like mapK might make sense because this is really just sugar for a partially applied K combinator.

const K = _.curry((x, y) => x);
_([1, 2, 3]).map(K('hi')) // => 'hi', 'hi', 'hi'

Although tbh, I'm not sure it warrants a function in the lib given how easy it is roll your own.

@vqvu vqvu mentioned this issue Nov 24, 2015
34 tasks
@vqvu
Copy link
Collaborator

vqvu commented Nov 24, 2015

Do we have a solution for deprecation warning ?

Besides updating the docs to say so? I don't think so.

I'm not sure it warrants a function in the lib given how easy it is roll your own.

Having a _.constant = K might make sense to supplement _.compose, _.curry and _.partial. For completeness.

I will add an entry in our grand list of 3.0 issues (#179).

@apaleslimghost
Copy link
Collaborator

Having a _.constant = K might make sense to supplement _.compose, _.curry and _.partial. For completeness.

This is another instance I think we should be moving towards less functions. We already have things like pluck which are just map plus some combinator. People can roll their own, or use Ramda (or lodash-fp, or prelude.ls, or [insert combinator library here]). I'd be fine with having a highland-kitchen-sink module once The Great Modularisation happens.

Edit:

Do we have a solution for deprecation warning ?

Node has util.deprecate, which warns when a function is used (and can be turned off by command line flags). It also works in browserify.

@svozza
Copy link
Collaborator

svozza commented Nov 24, 2015

Hehe. I was wondering when we'd see you, @quarterto , I remember the trouble I got into when I tried to add the I combinator.

@svozza
Copy link
Collaborator

svozza commented Nov 28, 2015

Fixed by #408

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants