Julia Universal Comparison Operator

Viewed 56

I usually use Crystal when I write my code. In Crystal, there is the <=> comparison operator. Usage is simple:

p! 404 <=> 405

This would print the following in my terminal:

404 <=> 405 # => -1

The printed value is -1, but if the integers in the equation were switched, it would print 1, as 405 is greater than 404. If the integers were equal, it would print 0.

I would like to use something similar in a Julia program I am writing, but can't seem to find an operator that works. I can of course use if-else if-else logic but I am really only concerned with storing the value in a database.

1 Answers

Is this what you want?

julia> cmp(404, 405)
-1

julia> cmp(404, 404)
0

julia> cmp(405, 404)
1
Related