Comment detail

全ての組み合わせ (Nested Flatten)
fiber でジェネレータにしました。

「(...)」 というのは可変長引数をあらわすオブジェクトです。でも、コレ使うのなんかクラッシュする。。。

あと、配列の分配がきれいにかけないです。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
CrossProduct: class {
    - _list: [];

    initialize: method(...) {
        (...).each_ordered_arg {
            // ここのコメントを削除するとなぜかクラッシュする^^
            if (it is String) {
                _list.push_back(it.split("").to_a);
            } else {
                _list.push_back(it);
            }
        }
    }

    all: method fiber {
        (fun (acc, rest) {
            if (rest.empty()) {
                yield acc;
            } else {
                x, xs: rest[0], rest.slice(1, rest.length);
                x {
                    callee(acc ~ [it], xs);
                }
            }
        })([], _list);
    }
}

c: CrossProduct([0, 1], "ab", ["Foo", "Bar"]);
c.all {
    it.p;
}

Index

Feed

Other

Link

Pathtraq

loading...