Skip to content

Non-mutating helpers to add/remove #128

@Frassle

Description

@Frassle

I'm finding quite a bit of code needs to do things like take a set and make a new set but with one extra element, or with one element removed. This quite often needs repeating with small variations. For example we're looking at using a Set[string] for the languages to run tests against, but some tests need to remove one or more languages. So what I'm writing helpers so that I can do

{ test: "1", languages: Remove(allLanguages, "go", "dotnet") },
{ test: "2", languages: Remove(allLanguages, "python") },

Feels like it might make sense to put something like this on set itself so I could do allLanguages.TBD("go").
Technically I don't think these methods are hard to write, but I'm a bit torn on two designs regarding names.

  1. Is to just add something like UnionWith(vals ...T) Set[T], but then it feels like maybe we should also do Intersect and SymmetricDifference, and then maybe the IsSub/Superset methods as well, and all of that feels maybe too busy. Although has some nice symmetry in that python allows any iterable for these methods.
  2. Is to name it something like Add/Remove to keep it limited to just a non-mutating adding and removing. But I'm not sure what's a good name for this, maybe With and Without.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions