background preloader

Functional Javascript

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. 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 Functional.map = 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] If object is supplied, it is the object of the call. The fusion rule: A synonym for select.

Azkaban | LinkedIn Data Team A batch job scheduler can be seen as a combination of the cron and make Unix utilities combined with a friendly UI. Batch jobs need to be scheduled to run periodically. They also typically have intricate dependency chains—for example, dependencies on various data extraction processes or previous steps. A good batch workflow system allows a program to be built out of small reusable pieces that need not know about one another. Why was it made? Schedulers are readily available (both open source and commercial), but tend to be extremely unfriendly to work with—they are basically bad graphical user interfaces grafted onto 20-year old command-line clients. State of the project We have been using Azkaban internally at LinkedIn for since early 2009, and have several hundred jobs running in it, mostly Hadoop jobs or ETL of some type. Any patches, bug reports, or feature ideas are quite welcome.

JS.Class - Ruby-style JavaScript In Ruby, modules and classes are just another type of object; they are objects that are responsible for storing methods and making new objects. Class methods are methods attached to (and called on) an individual class object, rather than its instances. They are really just a special case of singleton methods. To add class methods when defining a class, wrap them up in an extend block: We could equally add the methods after the class was created: These two syntaxes apply equally to creating and extending Modules. var james = User.create('James'); james.username // -> 'James' james.klass // -> User When you create a subclass, it will inherit any class methods of its parent, and you can use callSuper() too: Note how this, even in callSuper methods, always refers to the same thing as in the original method call. Note that class methods are not the same as Java’s static methods. User.define('copy', function() { return this.klass.create(this.username);});

Functional programming with JavaScript | Minko Gechev's blog This article is about the functional concepts of JavaScript. Some of them are built-in the languages, others extra implemented but all of them are very common for purely functional languages like Haskell. First I want to tell what I mean with the term purely functional language. Concurrency. I hope these arguments are enough for you to look at the next sections. Anonymous functions It seems that the functional programming becomes more and more popular. $(document).ready(function () { //do some stuff }); The function passed to $(document).ready is exactly an anonymous function. More about passing functions in the next section… High-order functions High-order functions are functions which accepts functions as arguments or returns functions. function animate(property, duration, endCallback) { //Animation here... if (typeof endCallback === 'function') { endCallback.apply(null); } } animate('background-color', 5000, function () { console.log('Animation finished'); }); Imagine we have this case:

The best way to load external JavaScript Posted at July 28, 2009 09:00 am by Nicholas C. Zakas Tags: Blocking, JavaScript, Performance Not too long ago, I wrote about loading JavaScript without blocking by creating a dynamic <script> tag. When <script> tags are in the flow of an HTML document, the browser must stop rendering and wait for the script file to download and execute before continuing (example). The best technique Steve Souders has explored several different ways to load JavaScript without blocking both on his blog and in his books. Create two JavaScript files. That’s it! function loadScript(url, callback){ var script = document.createElement("script") script.type = "text/javascript"; if (script.readyState){ //IE script.onreadystatechange = function(){ if (script.readyState == "loaded" || script.readyState == "complete"){ script.onreadystatechange = null; callback(); } }; } else { //Others script.onload = function(){ callback(); }; } script.src = url; document.getElementsByTagName("head")[0].appendChild(script); }

seanhess/fjs Extreme JavaScript Performance ramda-examples.md Ramda Examples Lift const madd3 = R.lift(R.curry(function (a, b, c) { // [1, 1, 1] // [1, 2, 1] // [1, 3, 1] // [2, 1, 1] // [2, 2, 1] // [2, 3, 1] // [3, 1, 1] // [3, 2, 1] // [3, 3, 1] console.log(arguments); return a + b + c; })); madd3([1, 2, 3], [1, 2, 3], [1]); //=> [3, 4, 5, 4, 5, 6, 5, 6, 7] composeK R.composeK(h, g, f) == R.compose(R.chain(h), R.chain(g), R.chain(f)) List Comprehension /* * Example: * Find any integer x, y, z that match the following conditions * 1. 0 < x < y < z < 10 * 2. x * x + y * y = z * z * In Python: * [(x,y,z) for x in range(1,10) for y in range(1,10) for z in range(1,10) if x < y and y < z and x * x + y * y == z * z] * >>> [(3, 4, 5)] * In Javascript with Ramda: */ var R = require('ramda'); R.pipe( R.sequence(R.of), R.filter(R.apply(function(x, y, z) { return x < y && y < z && (x * x + y * y == z * z); })) )([R.range(1, 10), R.range(1, 10), R.range(1, 10)]) // [[3, 4, 5]] Chain

LABjs (Loading And Blocking JavaScript)

Related: