This page provides the comparison tables of functional programming instructions between programming languages. Comparison of basic instructions of imperative paradigm is provided by the comparison of basic instructions.
For brevity, these words will have the specified meanings in the following tables (unless noted to be part of language syntax):
bool pred<T>(T t)
).identity lambda | lambda | map | apply | filter | fold | sum | |
---|---|---|---|---|---|---|---|
Python | lambda x: x | lambda args: expr | map(func, list) | nfunc(*arguments) | filter(pred, list) | functools.reduce(func2, list) | sum(list) |
Mathematica | #& | (expr)& (arguments are #1, #2, etc.)
Function[{args},expr] |
Map[func, list]
func /@ list |
Apply[nfunc, args]
nfunc@@args |
Select[list, pred] | Fold[func2, val, list] | Apply[Plus,list]
Plus@@list |
C#[1] | x => x | (args) => expr | Enumerable.Select(list, func) | Requires reflection | Enumerable.Where(list, pred) | Enumerable.Aggregate(list, func2)
Enumerable.Aggregate(list, val, func2) |
Enumerable.Sum(list)
Enumerable.Sum(list, func) |
Visual Basic .NET[1] | Function(x) x | Function(args) expr | |||||
F#[2] (can use Enumerable as well) | id(built-in)
fun x -> x |
fun pattern -> expr | Seq.map func list | Seq.filter pred list | Seq.fold func2 val list | Seq.sum list
Seq.sumBy func list |
sort | max | min | |
---|---|---|---|
Python | sorted(list) | max(list) | min(list) |
Mathematica | Sort[list] | Max[list] | Min[list] |
C#[1] | Enumerable.OrderBy(list, comp) | Enumerable.Max(list, func) | Enumerable.Min(list, func) |
Visual Basic .NET[1] | |||
F#[2] | Seq.sort list
Seq.sortBy comp list |
seq.max
seq.maxBy func list |
seq.min
seq.minBy func list |
group by | |
---|---|
Python | itertools.groupby(list, func)[3] |
Mathematica | GroupBy[list, func][wolfram 1] |
C#[1] | Enumerable.GroupBy(list, func) |
Visual Basic .NET[1] | |
F#[2] | seq.groupBy func list |
Generate range (lazily) | Infinite range (lazily) | |
---|---|---|
Python | xrange(start, end, step) (Python 2)[4]
range(start, end, step) (Python 3)[5] |
itertools.count(start, step) |
C#[1] | Enumerable.Range(start, count) | Enumerable.Range(start, Int32.MaxValue) |
Visual Basic .NET[1] | ||
F#[2] | seq { start..step..last } | Seq.initInfinite func |
![]() | Original source: https://en.wikipedia.org/wiki/Comparison of programming languages (functional programming).
Read more |