Skip to content

Conversation

@andrew-coleman
Copy link
Member

This PR introduces two new operators that can be used within a path expression:

  • @$var is used on a map step (.) to bind a variable to the current context item.
  • #$var is used to bind a variable to the current context position (in the sequence).

The former can be used to perform data cross referencing and joins - resolves #333.
The latter resolves #187
The documentation has been updated with details of these operators, plus a section on the explaining path processing model.

@coveralls
Copy link

coveralls commented Oct 1, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 828ae26 on join into db7cac7 on master.

mattbaileyuk
mattbaileyuk previously approved these changes Oct 1, 2019
Copy link
Member

@mattbaileyuk mattbaileyuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of really minor points, but happy with all the rest, so will approve this because those are small things that could be fixed later anyway.

@jugaadi
Copy link

jugaadi commented Oct 1, 2019

Can't we reduce it to just @var?

library.loans@l.books@b[$l.isbn=$b.isbn].{
  'title': $b.title,
  'customer': $l.customer
}

Same with #var

library.books#i['Kernighan' in authors].{
  'title': title,
  'index': $i
}

Alternative : An underscore to represent context computation. It can be extended just like functions.
Syntax : _<keyword specific symbol><var>, _<keywords>$<var>, or _<keyword> for current context.
Context Bindings :

  • Index - _@i or _index$i or $_index
  • Instance - _#o or _instance$o or $_instance
  • Type - _%t or _type$t or $_type
  • Parent - _$ or _parent$p or $_parent

Example :

library.books_#i['Kernighan' in authors].{
  'title': title,
  'index': $i
}
library.loans_@l.books_@b[$l.isbn=$b.isbn].{
  'sno': $_index
  'title': $b.title,
  'customer': $l.customer
}

@andrew-coleman
Copy link
Member Author

Thanks for the feedback @jugaadi. In one of my early prototypes, I did experiment with dropping the '$'. However, I felt that the dollar made the variable token consistent across the language. It is also used when binding variables using the := operator, even though it could be argued that that is not necessary either.

@mattbaileyuk mattbaileyuk merged commit 3cb51df into master Oct 2, 2019
@mattbaileyuk mattbaileyuk deleted the join branch October 2, 2019 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

how to "join" objects based on a common key $indexOf function for array enhancement request

5 participants