<=> ( obj1 obj2 -- <=> )
Factor documentation > Factor handbook > The language > Objects > Linear order protocol
Next:>=< ( obj1 obj2 -- >=< )


Vocabulary
math.order

Inputs and outputs
obj1an object
obj2an object
<=>an ordering specifier


Generic word contract
Compares two objects using an intrinsic linear order, for example, the natural order for real numbers and lexicographic order for strings.

The output value is one of the following:
+lt+ - indicating that obj1 precedes obj2
+eq+ - indicating that obj1 is equal to obj2
+gt+ - indicating that obj1 follows obj2


See also
>=<

Definition
IN: math.order

GENERIC: <=> ( obj1 obj2 -- <=> )


Methods
USING: accessors kernel math math.order sorting.human ;

M: alphanum <=>
[ obj>> ] bi@ 2dup [ integer? ] bi@ xor
[ drop integer? +lt+ +gt+ ? ] [ <=> ] if ;


USING: decimals kernel math.order ;

M: decimal <=>
2dup before? [ 2drop +lt+ ] [ equal? +eq+ +gt+ ? ] if ;
inline


USING: calendar math.order ;

M: duration <=> [ duration>years ] compare ;


USING: accessors io.pathnames math.order ;

M: pathname <=> [ string>> ] compare ;


USING: kernel math math.order ;

M: real <=>
2dup < [ 2drop +lt+ ] [ number= +eq+ +gt+ ? ] if ; inline


USING: kernel math.order sequences sequences.private ;

M: sequence <=>
[ mismatch ] 2keep pick
[ 2nth-unsafe <=> ] [ [ length ] compare nip ] if ;


USING: calendar classes.tuple math.order ;

M: timestamp <=> [ >gmt tuple-slots ] compare ;


USING: accessors compiler.cfg.ssa.interference math.order
sorting.slots ;

M: vreg-info <=>
{ { pre-of>> <=> } { def-index>> <=> } } compare-slots ;


USING: accessors arrays kernel math.order words ;

M: word <=> [ [ name>> ] [ vocabulary>> ] bi 2array ] compare ;