rtfeldman/seamless-immutable

Seamless Sort

开放

#182 创建于 2016年12月12日

 (10 条评论) (18 个反应) (0 位负责人)JavaScript (221 个派生)batch import
enhancementhelp wanted

仓库指标

星标
 (5,367 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

I'm using seamless in a substantial production project (and loving it by the way) and we are consistently struggling with one minor annoyance, .sort()

My daydream scenario is an override on any immutable array that gives me .sort() that does not mutate and returns an immutable copy, like map, filter, and reduce appear to do. But I'm open if there's a different preferred solution.

Right now we find ourselves using either [].concat(functionChain).sort(comparator) for when we MIGHT be immutable (IE when we're first wiring together some stuff) and functionChain.asMutabe().sort(comparator) for when we know we are.

This is working ok, so it isn't too urgent, but an override feels like it would be very elegant and result in much more readable and portable code. It also seems a little more 'seamless' ^_^

EDIT: I might note that I understand why it currently throws the error it does, and perhaps a seamless version of sort should be put under a different name, allowing the old mutating method to continue throwing an error. I think there may be some reasonable debate there and I'm not overly committed to either side.

贡献者指南