Giter Site home page Giter Site logo

Comments (3)

davidchambers avatar davidchambers commented on July 17, 2024

Such a function could be used to filter a string map by keys, or to create one record from another.

Modern JavaScript syntax suffices if the keys or field names are static:

> (({b, d}) => ({b, d})) ({a: 1, b: 2, c: 3, d: 4})
{b: 2, d: 4}
> (({x, y}) => ({x, y})) ({x: 0, y: 0, color: '#000'})
{x: 0, y: 0}

I prefer ({x, y}) => ({x, y}) to picks (['x', 'y']) because picks is difficult to describe in a Hindley–Milner type system (one must resort to an approximation such as Array String -> a -> b or Array String -> Object -> Object).

What do you think, @Siilwyn? Do you often find yourself filtering string maps by dynamic keys?

from sanctuary.

Siilwyn avatar Siilwyn commented on July 17, 2024

In most cases I'm filtering by static keys, I indeed often go with ({x, y}) => ({x, y}) however don't find it that nice to work with when the amount of keys and their length is long. In that case it often go multiline like:

({
  x,
  y,
  someLongKey,
}) =>
({
  x,
  y,
  someLongkey,
})

Which I don't find very readable and means if I change one of the keys I need to do it in two places.

If this method were to make it into Sanctuary, I would say it's mostly useful for big objects of which the values differ in type so having it only on string maps does sound less useful.

from sanctuary.

davidchambers avatar davidchambers commented on July 17, 2024

Thank you for the proposal, @Siilwyn. Currently I do not think the proposed function belongs in the library.

from sanctuary.

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.