版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

85 строки
1.8 KiB

  1. import { constFalse, constTrue, flow, pipe } from './function';
  2. var contramap_ = function (predicate, f) { return pipe(predicate, contramap(f)); };
  3. /**
  4. * @since 2.11.0
  5. */
  6. export var contramap = function (f) {
  7. return function (predicate) {
  8. return flow(f, predicate);
  9. };
  10. };
  11. /**
  12. * @category type lambdas
  13. * @since 2.11.0
  14. */
  15. export var URI = 'Predicate';
  16. /**
  17. * @category instances
  18. * @since 2.11.0
  19. */
  20. export var getSemigroupAny = function () { return ({
  21. concat: function (first, second) { return pipe(first, or(second)); }
  22. }); };
  23. /**
  24. * @category instances
  25. * @since 2.11.0
  26. */
  27. export var getMonoidAny = function () { return ({
  28. concat: getSemigroupAny().concat,
  29. empty: constFalse
  30. }); };
  31. /**
  32. * @category instances
  33. * @since 2.11.0
  34. */
  35. export var getSemigroupAll = function () { return ({
  36. concat: function (first, second) { return pipe(first, and(second)); }
  37. }); };
  38. /**
  39. * @category instances
  40. * @since 2.11.0
  41. */
  42. export var getMonoidAll = function () { return ({
  43. concat: getSemigroupAll().concat,
  44. empty: constTrue
  45. }); };
  46. /**
  47. * @category instances
  48. * @since 2.11.0
  49. */
  50. export var Contravariant = {
  51. URI: URI,
  52. contramap: contramap_
  53. };
  54. // -------------------------------------------------------------------------------------
  55. // utils
  56. // -------------------------------------------------------------------------------------
  57. /**
  58. * @since 2.11.0
  59. */
  60. export var not = function (predicate) {
  61. return function (a) {
  62. return !predicate(a);
  63. };
  64. };
  65. /**
  66. * @since 2.11.0
  67. */
  68. export var or = function (second) {
  69. return function (first) {
  70. return function (a) {
  71. return first(a) || second(a);
  72. };
  73. };
  74. };
  75. /**
  76. * @since 2.11.0
  77. */
  78. export var and = function (second) {
  79. return function (first) {
  80. return function (a) {
  81. return first(a) && second(a);
  82. };
  83. };
  84. };