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

List.map does not work with mapper that returns null or undefined #38

Open
pcardune opened this issue Nov 18, 2016 · 1 comment
Open

Comments

@pcardune
Copy link

Example:

var {Record, List} = require("typed-immutable");

var Point = Record({x: Number(0), y: Number(0)})
var Points = List(Point, "Points")
ps = Points.of({x:3}, {y: 5})
ps.map(a => a.x || null);

this throws a "TypeError: Cannot read property 'constructor' of null"

I believe what is happening here is that the type inferer is not correctly returning a new List(Maybe(Number)).

@stutrek
Copy link
Member

stutrek commented Nov 18, 2016

You might need to use List.reduce and a new List(Maybe(Number)) to do this, the behavior is as documented.

I wouldn't be against a way of telling List.map which type of list you want to end up with, that would let you use both Any or Maybe.

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

No branches or pull requests

2 participants