Wafl Home

List Tutorial

Function filterMap

Function filterMap(l,cond,f) is a combination of functions filter and map. It maps elements of list l by function f to a new list, but only including elements that satisfy condition cond. The element order is preserved.

Function filterMap(l,cond,f) is equivalent to

filterMap(l,cond,f) =
	l->filter(cond)->map(f);

but is more efficient, because it processes list l only once, with no construction of intermediate list.

Source code:

{#
[1,2,3,4,5]->filter(\x : x%2>0)->map(\x : x*x),
[1,2,3,4,5]->filterMap(\x : x%2>0,\x : x*x),
[1,2,3,4,5]->filter(\x : x%2>0),
[1,2,3,4,5]->filterMap(\x : x%2>0,\x:x),
[3,4,5]->map(\x : x*x),
[3,4,5]->filterMap(\x : true,\x : x*x)
#}

Result:

{# [1,9,25], [1,9,25], [1,3,5], [1,3,5], [9,16,25], [9,16,25] #}

 

Table of Contents

Let's Start

Program Structure

Primitive Data Types

List

Tuple

Record

HTML

Command Line Interpreter

Using Web Servers

Syntax

Examples

Tips

The most of examples evaluates with both command line and Web server Wafl interpreters. If any example is based on specific features of an interpreter, it is explicitly annotated.