Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compute #49

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lodash_idl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const lodashProps = `

get: Path
mapValues: Path
compute: Path

# Creates an array of values corresponding to paths of object.
at: [Path!]
Expand Down
9 changes: 9 additions & 0 deletions src/transformations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import maxBy from 'lodash-es/maxBy';
import meanBy from 'lodash-es/meanBy';
import sumBy from 'lodash-es/sumBy';
import join from 'lodash-es/join';
import expression from 'lodash-es/join';

import get from 'lodash-es/get';
import mapValues from 'lodash-es/mapValues';
Expand All @@ -40,10 +41,17 @@ import invertBy from 'lodash-es/invertBy';
import keys from 'lodash-es/keys';
import values from 'lodash-es/values';

const compute = function(scope, expression) {
return _.template("<%= " + expression + " %>")(scope);
}

const transformations = {
Array: {
each: (array, arg) => {
return map(array, item => applyTransformations(item, arg));
},
mapCompute: (array, arg) => {
return compute(array, item => applyTransformations(item, arg));
},
map,
keyBy,
Expand Down Expand Up @@ -84,6 +92,7 @@ const transformations = {
invertBy,
keys,
values,
compute,
},
Number: {
lt,
Expand Down