views:

104

answers:

4

I know about map/reduce alghoritm and its use. It's using functions that are called Mappers and Reducers, but I also find people use the word Filters.

Are Filters same as Mappers or is there some significant difference?

+7  A: 
Charlie Martin
Charlie -Small, well written answers like this make me wish I could up vote your answer twice.
Frank Rosario
So in short, filter is a map that uses the characteristic function.
Azder
Um, yes and no, @Azder. If you did a map with the same odd(x) function, you'd get { 1, 0, 1, 0, 1, 0, ...} A filter is really a projection; you it's *only* those elements forwhich the predicate holds.
Charlie Martin
@Frank, thanks very much. You could always get a second login ;-)
Charlie Martin
Thanks about that comment Charlie, I forgot the ranges of map and filter are different.
Azder
+1  A: 

Filter takes a "list" and a function, applies the function to every member of the list and returns a new list containing only members where the application of the function returned true. For instance:

l = [1,2,3,4]
l = filter(lambda x: x < 3, l)
print l # [1,2]

Map does the same thing, but returns a list containing the results of the function application:

l = [1,2,3,4]
l = map(lambda x: x < 3, l)
print l # [True,True,False,False]
Patrick
A: 

A filter determines if an item should be kept or removed. A mapper just translates the value in to another. As a consequence: The output set of a map operation is always equal in size with the input set. The output on a filter operation is smaller than the input set.

Emil H
A: 

Generally, map functions take an input set and a function, and returns a set containing the function output for each input element. A filter takes an input set and a boolean function, and returns a set containing the input values for which the function returns true.

Alex