Comments (3)
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.
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.
Thank you for the proposal, @Siilwyn. Currently I do not think the proposed function belongs in the library.
from sanctuary.
Related Issues (20)
- Possible example bug HOT 3
- How to create a function in 'sanctuary'? HOT 2
- State and Reader ADTs
- ES5 => ES6 HOT 1
- Bundled version contains refetences to undefined self HOT 4
- Deno version HOT 2
- Add a function to split an Array into equally sized chunks
- Idea: Only treat objects without prototypes as StrMaps HOT 6
- Be more explicit about S.get(s) being an escape hatch from type safety HOT 1
- Question about S.concat HOT 4
- Support logging S.Nothing in deno
- feat: Make types accessible by name in `S` HOT 1
- Remove the need for require ('util') in browser environment HOT 4
- Check for empty structures? HOT 1
- Searchbar on website https://sanctuary.js.org/ HOT 1
- Implement Types for all new EcmaScript objects.
- match has changed from version 3.1.0 HOT 2
- Refactor documentation to be more independent and catchy
- ECMAScript modules HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sanctuary.