A "high-level" language for the Gameboy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
592 B

  1. export const intersect = <A>(xs: Set<A>, ys: Set<A>): Set<A> => {
  2. const out: Set<A> = new Set()
  3. xs.forEach(x => {
  4. if (ys.has(x)) {
  5. out.add(x)
  6. }
  7. })
  8. return out
  9. }
  10. export const setEquals = <A>(xs: Set<A>, ys: Set<A>): boolean => {
  11. if (xs.size != ys.size) {
  12. return false
  13. }
  14. for (const x of Array.from(xs)) {
  15. if (!ys.has(x)) {
  16. return false
  17. }
  18. }
  19. return true
  20. }
  21. export const union = <A>(xs: Set<A>, ys: Set<A>): Set<A> =>
  22. new Set([
  23. ...Array.from(xs),
  24. ...Array.from(ys),
  25. ])