Skip to content

Lazy funcitons #87

Open
Open
@zerozoo-a

Description

@zerozoo-a
const L = {};
 // map
    L.map = function* map(collection, mapper) {
        for(const c of collection) {
            yield mapper(c);
        }
    }
 // filter
    L.filter = function* filter(collection, predicate) {
        for(const c of collection) {
            if (predicate(c)) yield c;
        }
    }
// index도 사용 가능..
function* map1 (col, mapper) {
    let i = 0;
    for(const c of col) {
        yield mapper(c, i++);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions