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

When we have array:build and map:build, then why do we also need array:of and map:of ? #481

Closed
dnovatchev opened this issue May 7, 2023 · 2 comments
Labels
Discussion A discussion on a general topic. XQFO An issue related to Functions and Operators

Comments

@dnovatchev
Copy link
Contributor

Looking at the current specification of the pairs of functions: (array:build, array:of) and (map:build, map:of), it is impossible not to notice that the second function in each of these pairs is a weak duplicate of the first.

Also, the examples provided for array:build and array:of, seem to have a good deal of common content / duplication / overlap.

Another issue is that array:of requires as input a sequence of value records, whose definition is challenging to understand (and whose meaning seems to be solely to represent a sequence of sequences), and what is also really challenging is how to construct this argument to array:of. If this is unnatural and challenging, one would probably prefer to use just array:build.

Is there an example where it is possible to construct an array (or a map) with array:of (or with map:of) but it is impossible (or significantly more difficult) to construct the same array/map with the function array:build (or with map:build)?

If there are no such significant and convincing examples, then why do we need the xxx:of functions?

Thus the question naturally arises: "Why is the function xxx:of necessary at all?"

@michaelhkay
Copy link
Contributor

michaelhkay commented May 7, 2023

Good question. array:of(X) is just array:build(X, function($x){$x?value}), with stronger typing on the type of the first argument. The reason for having it is that it provides an inverse to array:members() - you can decompose an array into "value records", manipulate the value records, and then reconstruct a new array. To do that with array:build you need to understand the internal structure of a "value record"; but perhaps you need to do that anyway.

Similarly, map:of(X) is just map:build(X, function($pair){$pair?key}, function($pair){$pair?value}), again with stronger typing, and the reason for having it is that it provides an inverse to map:pairs().

These are convenience functions, and it's valid to raise the question whether the convenience they offer is sufficient to justify including these functions in the library. Personally I think it probably is -- partly because of the extra type checking, which gives improved diagnostics, and partly because writing out the required callback functions is tedious and error-prone (I got them wrong in my first attempt) -- but it's a value judgement.

@ChristianGruen ChristianGruen added XQFO An issue related to Functions and Operators Discussion A discussion on a general topic. labels May 7, 2023
@ndw
Copy link
Contributor

ndw commented May 16, 2023

We agreed to close this issue with no action at meeting 034, 16 May 2023

@ndw ndw closed this as completed May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussion A discussion on a general topic. XQFO An issue related to Functions and Operators
Projects
None yet
Development

No branches or pull requests

4 participants