typed-immutable
typed-immutable copied to clipboard
List.map does not work with mapper that returns null or undefined
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)).
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.