Fandom

Planet JFX

Functional Programming

118pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

This is a simple example about using functions as parameters.

function reduce(f: function(Number,Number):Number, list: Number[], nilArg: Number):Number {
    if( list == [] ) then
        nilArg
    else
        f( list[0], reduce(f, list[x|indexof x > 0], nilArg))
}

function sum( x: Number, y: Number ): Number { x + y }

function product( x: Number, y: Number ): Number {x * y }

def list : Number[] = [1,2,3,4];

function p( s: String ) { println( s ); }

p("# sum     : {reduce(sum,list,0)}");
p("# product : {reduce(product,list,1)}");

Also on Fandom

Random Wiki