Last change
on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
725 bytes
|
Line | |
---|
1 | import { map } from './map';
|
---|
2 | export function pluck(...properties) {
|
---|
3 | const length = properties.length;
|
---|
4 | if (length === 0) {
|
---|
5 | throw new Error('list of properties cannot be empty.');
|
---|
6 | }
|
---|
7 | return (source) => map(plucker(properties, length))(source);
|
---|
8 | }
|
---|
9 | function plucker(props, length) {
|
---|
10 | const mapper = (x) => {
|
---|
11 | let currentProp = x;
|
---|
12 | for (let i = 0; i < length; i++) {
|
---|
13 | const p = currentProp != null ? currentProp[props[i]] : undefined;
|
---|
14 | if (p !== void 0) {
|
---|
15 | currentProp = p;
|
---|
16 | }
|
---|
17 | else {
|
---|
18 | return undefined;
|
---|
19 | }
|
---|
20 | }
|
---|
21 | return currentProp;
|
---|
22 | };
|
---|
23 | return mapper;
|
---|
24 | }
|
---|
25 | //# sourceMappingURL=pluck.js.map |
---|
Note:
See
TracBrowser
for help on using the repository browser.