RE: find() - initial sketch proposal

I think this is a viable and relatively straightforward first "stab". I'd like to suggest to extend this a little, for instance:

Add a one-argument signature:

    map:find($x as item()*) as array(*)

which is short-hand for map:find($x, ()). And change the current signature and description slightly:

      map:find($x as item()*, $keys as xs:anyAtomicType*) as array(*)

This function returns an array containing all values that are associated with a key in $keys in any map or array that is *contained in* the value of $x. If $keys is the empty sequence, it returns all values that are *contained in* the value of $x, irrespective of actual map key or array index.

This would make the function more powerful, without too much effort, and at the same time we don't have to fully support wild-card or regex matching. 

And I'd suggest we add a Note that makes explicit that $x does not need to contain only arrays and/or maps (even though this is implicitly clear from your description already):

Note: values in the sequence $x that are not arrays or maps are ignored.

> The order of members in the result array is implementation-dependent.

Should this perhaps only hold true for maps? Because if $x contains arrays, the order of these arrays can be maintained. Also, I think it makes sense if the order of the items in the sequence of $x should be maintained, or any sequences that are part of a value of a contained map. That is, suppose you have a sequence of two maps:

map:find(({'foo': 42}, {'foo': 43}), 'foo')

I would expect this to return (42, 43), not (43, 42). Of course, in a case like the following, the order can only be implementation-dependent:

map:find({ 'a': { 'bar' : 56},  'b': { 'bar': 57 } }, 'bar') 

Which can either return (56, 57) or (57, 56).

This thing with order would also be reflected with any attempt we make to create a function body that works as map:find.

Cheers,
Abel


> -----Original Message-----
> From: Michael Kay [mailto:mike@saxonica.com]
> Sent: Tuesday, July 26, 2016 6:49 PM
> To: Public Joint XSLT XQuery XPath
> Subject: map:find() - initial sketch proposal
> 
> Here's an first stab at a proposal for a map:find() function in response to bug
> 29743.
> 
>      map:find($x as item()*, $key as xs:anyAtomicType) as array(*)
> 
> This function returns an array containing all values that are associated with
> the key $key in any map that is *contained in* the value of $x
> 
> A map or array M is *contained in* a sequence S if any of the following
> conditions holds:
> 
> * M is an item in the sequence S (including the case where S is the single item
> M)
> 
> * M is *contained in* the value part of a key-value pair within a map that is
> itself *contained in* S
> 
> * M is *contained in* a member of an array that is itself *contained in* S
> 
> The order of members in the result array is implementation-dependent.
> 
> If nothing is found (including the case where $x is an empty sequence), the
> function returns an empty array.
> 
> Michael Kay
> Saxonica

Received on Wednesday, 27 July 2016 10:09:21 UTC