Advertisement
Guest User

Untitled

a guest
Aug 25th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. const { switchcaseD, switchcaseF, switchcaseA, switchcaseA2, switchcaseReverse, $Ω } = require ('./switch-alternatives.js')
  2.  
  3. console.clear()
  4. console.log('Examples: switch-alternatives.js'); console.log();
  5.  
  6. // ------------------------------------------------------------
  7. const mapperBest = switchcaseA({
  8. stringData: 'This is regular string data friends',
  9. functionData: () => ('the function worked')
  10. })(() => ('This will work with a function or straight data'))
  11.  
  12. // Each case.
  13. console.log('Testing switchcaseA()')
  14. console.log('1.', mapperBest('stringData'))
  15. console.log('2.', mapperBest('functionData'))
  16. console.log('3.', mapperBest())
  17. console.log('------------')
  18. console.log()
  19.  
  20. // An example.
  21. const mapperA2 = switchcaseA2({
  22. stringData: 'This is regular string data friends',
  23. functionData: () => ('the function worked')
  24. })(() => ('This will work with a function or straight data'))
  25.  
  26. // Each case.
  27. console.log('Testing switchcaseA2()')
  28. console.log('1.', mapperA2('stringData'))
  29. console.log('2.', mapperA2('functionData'))
  30. console.log('3.', mapperA2())
  31. console.log('------------')
  32. console.log()
  33.  
  34. // ------------------------------------------------------------
  35. const mapperFunc = switchcaseF({
  36. // Can't handle this version.
  37. // stringData: 'This is regular string data friends',
  38. functionData: () => ('the function worked')
  39. })(() => ('This will work ONLY with functions, the first one would fail if it were anything but'))
  40.  
  41. // Each case.
  42. console.log('Testing switchcaseF()')
  43. console.log('1.', mapperFunc('stringData'))
  44. console.log('2.', mapperFunc('functionData'))
  45. console.log('3.', mapperFunc())
  46. console.log('------------')
  47. console.log()
  48.  
  49. // ------------------------------------------------------------
  50. const mapper = switchcaseD({
  51. andric: 'hey there friend',
  52. amanda: 'get your hands off my wife!'
  53. })('I dunno, whatever dude')
  54.  
  55. // Each case.
  56. console.log('Testing switchcaseD()')
  57. console.log('1.', mapper('andric'))
  58. console.log('2.', mapper('amanda'))
  59. console.log('3.', mapper())
  60. console.log('------------')
  61. console.log()
  62.  
  63. const getDay = switchcaseD({
  64. 0: 'Sunday',
  65. 1: 'Monday',
  66. 2: 'Tuesday',
  67. 3: 'Wednesday',
  68. 4: 'Thursday',
  69. 5: 'Friday',
  70. 6: 'Saturday'
  71. })('Unknown')
  72.  
  73. const today = () => getDay(new Date().getDay())
  74.  
  75. console.log('Testing programatic switchcaseD()')
  76. console.log(today())
  77. console.log(new Date().getDay())
  78. console.log('------------')
  79. console.log()
  80.  
  81. // const async asyncCases = () => {
  82. // const case1 = await networkcall()
  83. // const case2 = await networkcall()
  84. // const case3 = await networkcall()
  85.  
  86. // return {
  87. // case1, case2, case3,
  88. // }
  89. // }
  90.  
  91. // ------------------------------------------------------------
  92. const programatic2 = switchcaseReverse('I dunno, whatever dude')({
  93. andric: 'hey there friend',
  94. amanda: 'get your hands off my wife!'
  95. })
  96.  
  97. // Each case.
  98. console.log('Testing switchcaseReverse()')
  99. console.log('1.', programatic2('andric'))
  100. console.log('2.', programatic2('amanda'))
  101. console.log('3.', programatic2())
  102. console.log('------------')
  103. console.log()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement