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

universal comparator #103

Open
genmeblog opened this issue Jun 25, 2024 · 3 comments
Open

universal comparator #103

genmeblog opened this issue Jun 25, 2024 · 3 comments

Comments

@genmeblog
Copy link

After fixing #99 some regression was introduced in tablecloth regarding comparison of any type. Till the last version, the following code was working. < or > could be treated as an universal comparator.

(tech.v3.datatype.argops/argsort tech.v3.datatype.functional/< ["ab" "bc"])
;; => [0 1]

Is it possible to make a comparator which acts universally on every type or should I reach for Clojure comparator?

@cnuernber
Copy link
Owner

cnuernber commented Sep 12, 2024

I think using clojure.core/compare as stated in the documentation makes sense to me. Here as some odd facts about clojure.core/compare --

user> (instance? java.util.Comparator clojure.core/compare)
true
user> 

Yet it is defined just like any other function in core... -- all AFunction's are comparators.

If you need to reverse the comparator then you can with a Comparator interface default function:

user> (require '[tech.v3.datatype.argops :as argops])
nil
user> (require '[tech.v3.datatype :as dt])
nil
user> (argops/argsort (.reversed clojure.core/compare) ["ab" "bc"])
[1 0]

So I don't think I want to add a dtype/functional wrapper for this as it seems reasonable to me.

@cnuernber
Copy link
Owner

I guess if you knew the datatype of the incoming thing then you could choose a specific comparator to use and default to the code in the compare data.

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

No branches or pull requests

2 participants