ImmutableSet.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace MathPHP\SetTheory;
  3. /**
  4. * Immutable Set (Set Theory)
  5. * A set that cannot be changed once created.
  6. *
  7. * Add, remove, and clear do not work on an immutable set. No Exceptions will
  8. * be thrown; it will just do nothing.
  9. *
  10. * Other than that, it acts just like a Set.
  11. */
  12. class ImmutableSet extends Set
  13. {
  14. /**************************************************************************
  15. * SINGLE MEMBER OPERATIONS - OVERIDDEN FROM SET
  16. * - Add (cannot add members)
  17. * - Add multi (cannot add members)
  18. * - Remove (cannot remove members)
  19. * - Remove multi (cannot remove members)
  20. * - Clear (cannot clear set)
  21. **************************************************************************/
  22. /**
  23. * Cannot add members to an immutable set
  24. *
  25. * @param mixed $x
  26. *
  27. * @return Set (this set unchanged)
  28. */
  29. public function add($x): Set
  30. {
  31. return $this;
  32. }
  33. /**
  34. * Cannot add members to an immutable set
  35. *
  36. * @param array<mixed> $members
  37. *
  38. * @return Set (this set unchanged)
  39. */
  40. public function addMulti(array $members): Set
  41. {
  42. return $this;
  43. }
  44. /**
  45. * Cannot remove members of an immutable set
  46. *
  47. * @param mixed $x
  48. *
  49. * @return Set (this set unchanged)
  50. */
  51. public function remove($x): Set
  52. {
  53. return $this;
  54. }
  55. /**
  56. * Cannot remove members of an immutable set
  57. *
  58. * @param array<mixed> $x
  59. *
  60. * @return Set (this set unchanged)
  61. */
  62. public function removeMulti(array $x): Set
  63. {
  64. return $this;
  65. }
  66. /**
  67. * Cannot clear an immutable set
  68. *
  69. * @return Set (this set unchanged)
  70. */
  71. public function clear(): Set
  72. {
  73. return $this;
  74. }
  75. }