Guest User

Untitled

a guest
Nov 12th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. const gt = x => y => x > y;
  2. const lt = x => y => x < y;
  3.  
  4. const or = x => y => x || y;
  5. const and = x => y => x && y;
  6.  
  7. const type = x => typeof x;
  8. // like type('foo') => 'string';
  9. // like type(undefined) => 'undefined';
  10.  
  11. const equal = x => y => x === y;
  12. // like eq(false)(false) => true;
  13. // like eq(false)(true) => false;
  14.  
  15. const nequal = x => y => x !== y;
  16. // like neq(false)(true) => true;
  17. // like neq(true)(true) => false;
  18.  
  19. const $typeof = x => y => equal(x)(type(y));
  20. // like $typeof('string')('foo') => true;
  21. // like $typeof('undefined')(undefined) => true;
  22. // like $typeof('boolean')('fizzbuzz') => false;
  23.  
  24. const undef = x => $typeof('undefined')(x);
  25. // like undef(undefined) => true;
  26. // like undef('foo') => false;
  27.  
  28. const def = x => nequal(type(x))('undefined');
  29. // like def(undefined) => false;
  30. // like def('foo') => true;
  31.  
  32. const gte = x => y => or(gt(x)(y))(eq(x)(y));
  33. const lte = x => y => or(lt(x)(y))(eq(x)(y));
  34.  
  35. const ss = x => y => or(or(and(gt(x)(y))(1))(and(gt(y)(x))(-1)))(0);
  36. // like ss(10)(1) => 1;
  37. // like ss(1)(10) => -1;
  38. // like ss(1)(1) => 0;
  39.  
  40. const is = x => y => x.__proto__.isPrototypeOf(new y());
  41. // like is(x)(Array); => true;
  42. // like is(true)(String) => false;
  43.  
  44. const is_not = x => y => equal(is(x)(y))(false);
  45.  
  46. const is_null = x => equal(x)(null);
  47.  
  48. export {
  49. gt,
  50. lt,
  51. and,
  52. or,
  53. type,
  54. equal,
  55. nequal,
  56. undef,
  57. def,
  58. gte,
  59. lte,
  60. ss,
  61. is,
  62. is_not,
  63. is_null
  64. };
Add Comment
Please, Sign In to add comment