mtso / hof

Higher-order functions in different languages.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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);

About

Higher-order functions in different languages.


Languages

Language:TypeScript 12.3%Language:PureScript 10.4%Language:Elm 9.0%Language:Haskell 7.6%Language:C++ 5.9%Language:Python 5.4%Language:Swift 5.0%Language:PHP 4.8%Language:C# 4.7%Language:Kotlin 4.1%Language:Go 4.0%Language:Ruby 3.9%Language:D 3.9%Language:JavaScript 3.5%Language:Rust 3.3%Language:R 3.0%Language:Standard ML 2.5%Language:Raku 2.4%Language:Common Lisp 2.1%Language:Clojure 1.5%Language:F# 0.8%