开发者

Web programming with higher order functions

开发者 https://www.devze.com 2023-01-25 19:45 出处:网络
We are learning higher-order functions in our class and our professor mentioned that they can be useful for web p开发者_JS百科rogramming. I\'m unsure as to what cases in which that would be true and w

We are learning higher-order functions in our class and our professor mentioned that they can be useful for web p开发者_JS百科rogramming. I'm unsure as to what cases in which that would be true and was wondering if anyone had any experiences with higher-order functions in some common web programming tasks, and in what situations they would be useful.

I read through our book, but web programming wasn't mentioned, I suppose it was just something the professor mentioned off topic, but it sparked my interest a bit.

Thanks!


I'm not exactly sure which cases your professor might have been talking about, but higher order functions are used heavily in JavaScript. A simple example of a higher order function (a function taking a function as a parameter and/or returning a function as a result) would be the jQuery ready() function:

$(document).ready(function(){
    alert('The DOM is ready for manipulation!');
});

A simple example, yes...but it demonstrates how useful higher order functions can be.


Play, (Scala) Lift (Scala) , SeaSide (Smalltalk) and Webmachine (Erlang) are three web frameworks the rely heavily on functional ideoms such as higher-order-functions.


Clojure makes extensive use of higher order functions for web development in the excellent Ring framework. See this excellent video which explains some of the concepts.

The basic idea is:

  • A web application is really just a function that maps a request to a response
  • You can therefore compose the entire web application using higher order functions
0

精彩评论

暂无评论...
验证码 换一张
取 消