This project is part of the @thi.ng/umbrella monorepo.
General purpose comparator with optional delegation for types
implementing the @thi.ng/api/ICompare
interface.
This feature was previously part of the @thi.ng/api package.
yarn add @thi.ng/compare
None
import { ICompare } from "@thi.ng/api";
import { compare } from "@thi.ng/compare";
class Foo implements ICompare<Foo> {
x: number;
constructor(x: number) {
this.x = x;
}
compare(o: Foo) {
return compare(this.x, o.x);
}
}
compare(new Foo(1), new Foo(2));
// -1
- Karsten Schmidt
© 2018 Karsten Schmidt // Apache Software License 2.0