Skip to content

A better "extend" function. Any comments ? #92

@tvsudhir

Description

@tvsudhir

I was trying to rewrite the "extend" function by introducing more combinators and make it look better. Please do comment on this.

// This function should be renamed ... Any suggestions ??
function objMapWith( fn ) {
    return function ( obj ) {
        Object.keys( obj ).forEach( function (key) {
            fn(key, obj[key]);
        });
    };
}

// This is not pure function but might be the required one.
// Comments ?? 
function addPropTo( obj ) {
    return function (key, val) {
        return obj[key] = val;
    }
}

extend = variadic( function (consumer, providers) {
    mapWith( objMapWith( addPropTo( consumer )))( providers );

    return consumer;
});

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