-
Notifications
You must be signed in to change notification settings - Fork 696
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #2444
- Loading branch information
Showing
5 changed files
with
76 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
function Comparable<T>(impl: { compare(a: T, b: T): number }) { | ||
return { | ||
...impl, | ||
|
||
equal(a: T, b: T) { | ||
return impl.compare(a, b) === 0; | ||
}, | ||
}; | ||
} | ||
|
||
const BooleanComparable = Comparable<boolean>({ | ||
compare(a, b) { | ||
return +a - +b; | ||
}, | ||
}); | ||
|
||
/** @namespace */ | ||
export const Boolean = { | ||
...BooleanComparable, | ||
hasInstance(value: unknown): value is boolean { | ||
return typeof value === "boolean"; | ||
}, | ||
}; | ||
|
||
const NumberComparable = Comparable<number>({ | ||
compare(left, right) { | ||
return left === right ? 0 : left < right ? -1 : 1; | ||
}, | ||
}); | ||
|
||
/** @namespace */ | ||
export const Number = { | ||
...NumberComparable, | ||
hasInstance(value: unknown): value is number { | ||
return typeof value === "number"; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters