Skip to content

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

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;
});

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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