mobily / ts-belt

🔧 Fast, modern, and practical utility library for FP in TypeScript.
https://mobily.github.io/ts-belt
MIT License
1.08k stars 30 forks source link

Support Set operations #69

Closed ivan-kleshnin closed 1 year ago

ivan-kleshnin commented 1 year ago

Hi! Do you have plans to support Set operations in this library? Maybe in future? Builtin Set is even more limited than Array so it would defenitely benefit from additional helpers. No other comparable library does it so far, AFAIK.

Letter S is already taken though 😅:

const E = {
  intersection<T>(setA: Set<T>, setB: Set<T>): Set<T> {
    return new Set([...setA].filter(element => setB.has(element)))
  },

  difference<T>(setA: Set<T>, setB: Set<T>): Set<T> {
    return new Set([...setA].filter(element => !setB.has(element)))
  },
}

E.intersection(new Set(["foo", "bar"]), new Set(["bar", "spam"]))
// => new Set(["bar"])

E.difference(new Set(["foo", "bar"]), new Set(["bar", "spam"]))
// => new Set(["foo"])
mobily commented 1 year ago

@ivan-kleshnin unfortunately no, I don't consider adding Set helpers at the moment, sorry!