This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Validator = require('simple-validate'); | |
| var validateTenantArgs = Validator.validateOrThrow({ | |
| title: 'somePred', | |
| etc: '...' | |
| }); | |
| // current style | |
| function postTenantToSystemTenant(systemTenant, tenantArgs) { | |
| validateTenantArgs(tenantArgs); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // `proxy` is a function to allow for point-free recursion in JavaScrpipt | |
| // it takes in a function name as a string, and returns a proxy function to the original function | |
| // examples | |
| // explicit proxy - save proxy after declaration | |
| // var length = ifElse(isEmpty, always(0), compose(inc, proxy('length'), tail)); | |
| // proxy('length', length); | |
| // use short had proxy chaining |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var R = require('ramda'); | |
| // `proxy` is a function to allow for point-free recursion in JavaScrpipt | |
| // it takes in a function name as a string, and returns a proxy function to the original function | |
| var factorial = R.ifElse( | |
| R.eq(0), R.always(1), | |
| R.converge(R.multiply, R.I, R.compose(proxy('factorial'), R.dec)) | |
| ); | |
| factorial(0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // functional helpers assumed to be included | |
| // `proxy` is a function to allow for point-free recursion in JavaScrpipt | |
| // it takes in a function name as a string, and returns a proxy function to the original function | |
| var length = ifElse(isEmpty, always(0), compose(inc, proxy('length'), tail)); | |
| length([]); | |
| // => 0 | |
| length([1, 2, 3, 4]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var R = require('ramda'); | |
| var factorOf = R.curryN(2, R.compose(R.eq(0), R.flip(R.modulo))); | |
| var getFizzBuzz = R.cond( | |
| [R.and(factorOf(3), factorOf(5)), R.always('FizzBuzz')], | |
| [factorOf(3), R.always('Fizz')], | |
| [factorOf(5), R.always('Buzz')], | |
| [R.T, R.identity] | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| getFizzBuzz :: (Int, Int, Int) -> String | |
| getFizzBuzz (_, 0, 0) = "FizzBuzz" | |
| getFizzBuzz (_, 0, _) = "Fizz" | |
| getFizzBuzz (_, _, 0) = "Buzz" | |
| getFizzBuzz (x, _, _) = show x | |
| fizzBuzz :: Int -> [String] | |
| fizzBuzz n = [getFizzBuzz (x, x `mod` 3, x `mod` 5) | x <- [1..n]] | |
| fizzBuzz 15 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var R = require('ramda'); | |
| // flipped filter to work with folds -> (acc, fn) | |
| // [a] -> [(a -> Boolean)] -> [a] | |
| var reduceWithFilter = R.reduce(R.flip(R.filter)); | |
| // (a -> b) -> [a] -> [(a -> Boolean)] -> [a] | |
| function listComp(outputFn, inputSet, predicates) { | |
| return R.compose(R.map(outputFn), reduceWithFilter(inputSet))(predicates); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var R = require('ramda'); | |
| // * -> IO | |
| var report = R.bind(console.log, console); | |
| // * -> IO | |
| var reportSuccess = R.compose(report, R.always('Success')); | |
| // * -> * -> IO | |
| var reportFailure = function(expected, actual) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var _ = require('ramda'), | |
| curry = _.curry, | |
| compose = _.compose; | |
| var fnames = [ | |
| 'map', | |
| 'forEach', | |
| 'concat' | |
| // TODO: add more |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * General Functional Helpers | |
| */ | |
| function compose(a, b) { | |
| return function() { | |
| a(b.apply(null, arguments)); | |
| }; | |
| } | |
| function is(v1, v2) { |