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

前端 未结 30 1231
夕颜
夕颜 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

    Personally, I like .With(). If I was using the object, after reading the documentation or the code comments, it would be clear what it does, and it reads ok in the source code.

    object.With("My new item as well");
    

    Or, you add "Along" with it.. :)

    object.AlongWith("this new item");
    

提交回复
热议问题