Compare pakage - set of the classes/types for make your structures comparable and orderable.
npm i @rslike/cmp
yarn add @rslike/cmp
pnpm add @rslike/cmp
- Install package
- In your entry file write next:
// your main file
// add global types in globalThis Some,None,Option, Result,Ok,Err functions
import "@rslike/cmp/globals";
// rest your file
Available by link: https://github.com/vitalics/rslike/wiki
This package patch Symbol
and global object. So to make sure that this package is works correctly - you need to import 1 time-only @rslike/cmp/globals
Example:
// entry.ts
import "@rslike/cmp/globals";
// file.ts
const a = {
// works!
[Symbol.compare]() {
return 1;
},
};
This package exports next useful functions/types/constants:
- Utilities functions (
compare
,equals
,partialEquals
) - Types (
Eq
,Ord
,PartialEq
) - Symbols (
Symbol.compare
,Symbol.equals
,Symbol.partialEquals
)
Example:
import { compare } from "@rslike/cmp";
compare(2, 3); // -1