Giter Club home page Giter Club logo

Comments (10)

jdalton avatar jdalton commented on May 4, 2024

_.pick and _.drop are object filter methods, currently accepting property names to include/exclude. I bet we could extend those to use a callback similar to how _.countBy, _.groupBy, and _.sortBy allow a callback or a property name.

from lodash.

shanimal avatar shanimal commented on May 4, 2024

Overloading _.pick and _.drop seems like a great plan.

_.screen({a:1,b:2,c:3},function(item){return item!==2})
// {a=1, c=3}

_.pick({a:1,b:2,c:3},["a","c"])
// {a=1,c=3}

As a side note, any idea why _.each doesn't return an object with callback results.

function fn(list,fn){
    var o = new list.constructor();
    _.each(list,function(i,k,l){
        o[k] = fn(i);
    });
    return o;
}
fn({a:1,b:2,c:3},function(i,k,l){return i*=2;});
// {a=2,b=4,c=6}

from lodash.

jdalton avatar jdalton commented on May 4, 2024

@shanimal

As a side note, any idea why _.each doesn't return an object with callback results.

_.each returns the collection passed to it.

from lodash.

 avatar commented on May 4, 2024

@shanimal Regarding _.each: you're actually looking for _.map.

from lodash.

shanimal avatar shanimal commented on May 4, 2024

Hi @kitcambridge

Actually _.map returns an array. I want an object with the keys preserved.

function fn(list,fn){
    var o = new list.constructor();
    _.each(list,function(i,k,l){
        o[k] = fn(i);
    });
    return o;
}
var o = {a:1,b:2,c:3};
fn(o,_.identity); // {a=1,b=2,c=3}
_.map(o,_.identity); // [1,2,3]

from lodash.

jdalton avatar jdalton commented on May 4, 2024

@shanimal I patched _.pick and _.drop, you should be good to go.

from lodash.

shanimal avatar shanimal commented on May 4, 2024

@jdalton That's awesome! Thanks.

from lodash.

 avatar commented on May 4, 2024

@shanimal Whoops, I completely missed what you were trying to do. _.map definitely won't work, then. Apologies.

from lodash.

shanimal avatar shanimal commented on May 4, 2024

np @kitcambridge thanks for the feedback.

from lodash.

lock avatar lock commented on May 4, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

from lodash.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.