Jun. 22nd, 2009

microwtf

Jun. 22nd, 2009 11:58 am
juan_gandhi: (Default)

public void setSettingValue(int value);
juan_gandhi: (Default)
And whether I should describe the whole beauty of this "to the people"...

public abstract class Monoid<X>
{
    abstract X unit();
    abstract X m(X x, X y);
    
    public X fold(Iterable<X> source) {
        X result = unit();
        for (X x : source) {
            result = m(result, x);   
        }
        return result;
    }
    
    public X fold(X[] source) {
        X result = unit();
        for (X x : source) {
            result = m(result, x);   
        }
        return result;
    }

    public final static Monoid<Integer> INT = new Monoid<Integer>() {
        Integer unit() { return 0; }
        Integer m(Integer x, Integer y) { return x + y; }
    };

    public final static Monoid<Double> DOUBLE = new Monoid<Double>() {
        Double unit() { return 0.; }
        Double m(Double x, Double y) { return x + y; }
    };

    public final static Monoid<String> STRING = new Monoid<String>() {
        String unit() { return ""; }
        String m(String x, String y) { return x + y; }
    };
    
    public static void main(String[] args) {
        System.out.println(STRING.fold(new String[]{"this ", "is ", "a ", "string!"}));
        System.out.println(INT.fold(new Integer[]{1, 2, 3, 4, 5}));
    }
}


juan_gandhi: (Default)
So, I'm not doing anything tonight. Nothing. Nada. Nincs. Nic. naniga.

Weird, weird feeling.
juan_gandhi: (Default)
keyboard is out at Google!

(Ну и как обычно в таких случаях, надо будет поправить список т.наз. друзей в линктине, которые успешно вывели на орбиту мою клавку но не потрудились сообщить мне об этом интересном факте.)

Profile

juan_gandhi: (Default)
Juan-Carlos Gandhi

September 2025

S M T W T F S
 1 23456
78910111213
14151617181920
21222324252627
282930    

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 2nd, 2025 09:05 pm
Powered by Dreamwidth Studios