What's the best name for a non-mutating “add” method on an immutable collection?

前端 未结 30 1243
夕颜
夕颜 2020-11-29 16:47

Sorry for the waffly title - if I could come up with a concise title, I wouldn\'t have to ask the question.

Suppose I have an immutable list type. It has an operat

30条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-29 17:26

    list.CopyWith(element)

    As does Smalltalk :)

    And also list.copyWithout(element) that removes all occurrences of an element, which is most useful when used as list.copyWithout(null) to remove unset elements.

提交回复
热议问题