background preloader

Functional Programming For The Rest of Us

Functional Programming For The Rest of Us

CoffeeScript Use functional programming techniques to write elegant JavaScript Introduction Functional programming languages have been in academia for quite some time, but historically they do not have extensive tools and libraries available. With the advent of Haskell in the .NET platform, functional programming is becoming more popular. Some traditional programming languages, such as C++ and JavaScript, import constructs and features from functional programming. Because functional programming encompasses a very different way of composing programs, programmers who are used to the imperative paradigm can find it difficult to learn. Functional programming concepts, including anonymous functions, different ways to call functions, and how to pass functions as arguments to other functions. Back to top Functional programming concepts Many developers know how to code in languages where you specify the method of solving a problem by describing "how." Listing 1. int factorial (int n) { if (n <= 0) return 1; else return n * factorial (n-1); } Listing 2. Anonymous functions Or

Functional Javascript var Functional; Functional is the namespace for higher-order functions. Functional.install = function(except) This function copies all the public functions in Functional except itself into the global namespace. If the optional argument is present, functions named by its property names are not copied. Higher-order functions Functional.compose = function(fn...) Type: (a2 → a1) (a3 -> a2)… (a… -> an) -> a… -> a1 Returns a function that applies the last argument of this function to its input, and the penultimate argument to the result of the application, and so on. (1, 2, 3…, )() =def 1(2(3(…((…))))) compose('1+', '2*')(2)→ 5 Functional.sequence = function(fn...) Type: (a… → a1) (a1 -> a2) (a2 -> a3)… (an-1 -> an) -> a… -> an Same as compose, except applies the functions in argument-list order. (1, 2, 3…, )(…) =def (…(3(2(1(…))))) sequence('1+', '2*')(2)→ 6 = function(fn, sequence, object) Type: (a ix → boolean) [a] -> [a] Applies fn to each element of sequence. map('1+', [1,2,3])→ [2, 3, 4]

PHPUnit Support After you set up PHPUnit, Web IDE greatly helps you to run your tests. Namely, to quickly create test run configuration: Right-click the desired target: a directory or a PHP file in the Project view, or a test class/method name in the code editorChoose Run<name> to start or Create<name> to specify additional parameters That’s it! XML configuration file Advanced settings can be specified through PHPUnit configuration file. Test groups A test can be tagged as belonging to one or more groups using the @group annotation as shown below. The test is run if none of the specified groups is excluded and at least one group is included. Run/Debug Tests Before you execute tests, please set up PHP home directory (one that contains PHP executable) in Settings | PHP. Test results window You can easily navigate from tests results tree and stack trace to the corresponding source code location. When debugging your tests you get all the features, such as watches, expressions evaluation, etc. Test with pleasure!