Reading Note of MapReduce: Simplified Data Processing on Large Clusters

=======================================================================
Reading Note of MapReduce: Simplified Data Processing on Large Clusters
=======================================================================

------
Origin
------
``map`` and ``reduce`` are primitives in Lisp.

``map`` example
::
    (map 'list #'- '(1 2 3 4)) =>  (-1 -2 -3 -4)
   
``reduce`` example
::
    (reduce #'* '(1 2 3 4 5)) =>  120

Haskell has the same functions.
``map`` example
::
    Prelude> map negate [1, 2, 3]
    [-1,-2,-3]
In Haskell, reduce is called fold. Haskell has 2 kinds of folds: foldl and
foldr.
::
    Prelude> foldl (+) 0 [1, 2, 3]
    6

-------
Example
-------
::
    map(String key, String value);
    // key: document name
    // value: document contents
    for each word w in value:
        EmitIntermeidate(w, "1");

    reduce(String key, Iterator values):
        // key: a word
        // values: a list of counts
        int result = 0;
        for each v in values:
            result += ParseInt(v);
        Emit(AsString(result));

你可能感兴趣的:(mapreduce,haskell,lisp)