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

System-provided operators could be used as functions #615

Open
b1conrad opened this issue Aug 17, 2022 · 0 comments
Open

System-provided operators could be used as functions #615

b1conrad opened this issue Aug 17, 2022 · 0 comments

Comments

@b1conrad
Copy link
Member

The operator usage is so convenient for chaining that we allowed user-defined functions to be used as operators. So, for example, these two usages are equivalent:

my_func(a,b,c)
a.my_func(b,c)

Unfortunately, the converse isn't true. These two usages (of a system-defined operator) are NOT equivalent:

append(a,b) // doesn't work as might be expected
a.append(b)

If system-provided operators could be used as functions, then we could write the flatten operation in a simpler way (as this author expected (see this commit)):

list_of_arrays.reduce(append) // note that this does NOT work now

One could extend this to sets:

list_of_arrays.reduce(union,[]) // note that this does NOT work now, but the next line does work though less simple
list_of_arrays.reduce(function(a,b){a.union(b)},[])

(Note that append works without an initial empty array, but since the first array in list_of_arrays might not be a set (might have duplicates) we need to seed the operation with an empty array.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant