Kaelinator / hopps

Complex data manipulation made easy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow burrowing of arrays

Kaelinator opened this issue · comments

The user should be able to deal with arrays just as easily as with objects using brackets.

For example,
hopps.set('[0..2]', [], 'hi!')
should yield
[ 'hi!', 'hi!', 'hi!' ]

And
hopps.get('a[0..1].b', { a: [ { b: 55, c: 42 }, { b: 9, c: 42 } ] })
should result in
[ 55, 9 ]

Array operations should follow haskell's syntax.

Okay, not exactly haskell's syntax.

Just a list:

'[1, 2, 3]' //=> [1, 2, 3]

Dots:

'[0..10]' // => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
'[1, 3, 5, 6..10]' // => [1, 3, 5, 6, 7, 8, 9]

Negatives:

/* the array being targeted contains [0, 1, 1, 2, 3, 5, 8, 13, 21] */
'[0..0]' // => [0, 1, 1, 2, 3, 5, 8, 13, 21]
'[4..0]' // => [3, 5, 8, 13, 21]
'[4..-1]' // => [3, 5, 8, 13]
'[4..-2]' // => [3, 5, 8]

Mod filter:
Executes .filter on the resulting list from the expression, allowing only truthy values to remain.

/* filters out falsy values and only allows truthy values */
'[5..10%2]' //=> [5, 7, 9] Since 5 % 2 == 1 and 1 is truthy, 5 is included

/* ! (not) should filter out truthy */
'[5..10!%2]' // => [6, 8] Since 5 % 2 == 1 and !1 is falsy, 5 is omitted

'[1..7%3, 8..13!%5]' //=> [1, 2, 4, 5, 10]

Bracket syntax should allow a user to access an object property that contains a dot (.).

hopps.get('[..hi].a', { ..hi: { a: 54 } }) => 54

Bracket syntax should also allow for multiple object properties to be referenced:

hopps.get('a[b, c]', { a: { b: 16, c: 64 } }) => [16, 64]