Higher-order functions in different languages.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
R.R
README.md
c++.cpp
clojure.clj
csharp.cs
d.d
fsharp.fs
go.go
haskell.hs
javascript.js
lisp.lisp
perl6.pl6
php.php
python.py
python3.py
ruby.rb
rust.rs
standard-ml.sml
swift.swift

README.md

Higher-Order Functions

Higher-order functions in different languages. Inspired by: FizzBuzz and hello-world.

Higher-order functions (HOF) are functions that satisfy one or both rules:

  • Returns a function.
  • Take one or more function parameters.

Spec

The two example higher-order functions are:

add

add takes an integer as a parameter and returns a second function that takes an integer, which returns the overall result.

type signature
function(int) -> function(int) -> int

each

each is a void function takes a list as its first parameter and a function as its second parameter. It then iterates over the given list passing in each element into the function.

type signature
function([int], function(int) -> void) -> void

Example Usage

Show how the function is used by calling them in the program's entry point. For example:

const three = add(1)(2);
each([1, 2, 3], console.log);