typed-immutable icon indicating copy to clipboard operation
typed-immutable copied to clipboard

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

Open pcardune opened this issue 9 years ago • 1 comments
trafficstars

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)).

pcardune avatar Nov 18 '16 05:11 pcardune

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.

stutrek avatar Nov 18 '16 15:11 stutrek