-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from poteat/poteat/new-reified-implementations
Add reified implementations for various methods
- Loading branch information
Showing
28 changed files
with
423 additions
and
52 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,67 @@ | ||
export function deepEqual(a: unknown, b: unknown): boolean { | ||
if (Object.is(a, b)) return true | ||
|
||
if ( | ||
a && | ||
b && | ||
typeof a === 'object' && | ||
typeof b === 'object' && | ||
Object.getPrototypeOf(a) === Object.getPrototypeOf(b) | ||
) { | ||
if (Array.isArray(a)) { | ||
if (!Array.isArray(b)) return false | ||
if (a.length !== b.length) return false | ||
for (let i = 0; i < a.length; i++) { | ||
if (!deepEqual(a[i], b[i])) return false | ||
} | ||
return true | ||
} | ||
|
||
if (a instanceof Map) { | ||
if (!(b instanceof Map)) return false | ||
if (a.size !== b.size) return false | ||
for (const [key, val] of a) { | ||
if (!b.has(key)) return false | ||
if (!deepEqual(val, b.get(key))) return false | ||
} | ||
return true | ||
} | ||
|
||
if (a instanceof Set) { | ||
if (!(b instanceof Set)) return false | ||
if (a.size !== b.size) return false | ||
for (const val of a) { | ||
if (!b.has(val)) return false | ||
} | ||
return true | ||
} | ||
|
||
if (a instanceof Date) { | ||
if (!(b instanceof Date)) return false | ||
return a.getTime() === b.getTime() | ||
} | ||
|
||
if (a instanceof RegExp) { | ||
if (!(b instanceof RegExp)) return false | ||
return a.toString() === b.toString() | ||
} | ||
|
||
const aKeys = Object.keys(a as Record<string, unknown>) | ||
const bKeys = Object.keys(b as Record<string, unknown>) | ||
if (aKeys.length !== bKeys.length) return false | ||
|
||
for (const key of aKeys) { | ||
if ( | ||
!deepEqual( | ||
(a as Record<string, unknown>)[key], | ||
(b as Record<string, unknown>)[key] | ||
) | ||
) | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
return false | ||
} |
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 |
---|---|---|
|
@@ -49,3 +49,19 @@ type TrueList< | |
export interface AndAll extends Kind.Kind { | ||
f(x: Type._$cast<this[Kind._], boolean[]>): _$andAll<typeof x> | ||
} | ||
|
||
/** | ||
Check warning on line 53 in src/boolean/and-all.ts GitHub Actions / build-stress
|
||
* Given a list of booleans, return whether all elements are true. | ||
* | ||
* @param {boolean[]} b - The list of booleans. | ||
Check warning on line 56 in src/boolean/and-all.ts GitHub Actions / build-stress
|
||
* | ||
* @example | ||
* ```ts | ||
* import { Boolean } from "hkt-toolbelt"; | ||
* | ||
* const result = Boolean.andAll([true, true, true]) | ||
* // ^? true | ||
* ``` | ||
*/ | ||
export const andAll = ((b: boolean[]) => | ||
b.every((e) => e)) as Kind._$reify<AndAll> |
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 |
---|---|---|
|
@@ -56,3 +56,19 @@ interface And_T<T extends boolean> extends Kind.Kind { | |
export interface And extends Kind.Kind { | ||
f(x: Type._$cast<this[Kind._], boolean>): And_T<typeof x> | ||
} | ||
|
||
/** | ||
Check warning on line 60 in src/boolean/and.ts GitHub Actions / build-stress
|
||
* Given two booleans, return whether both are true. | ||
* | ||
* @param {boolean} a - The first boolean. | ||
Check warning on line 63 in src/boolean/and.ts GitHub Actions / build-stress
|
||
* @param {boolean} b - The second boolean. | ||
Check warning on line 64 in src/boolean/and.ts GitHub Actions / build-stress
Check warning on line 64 in src/boolean/and.ts GitHub Actions / build-stress
|
||
* | ||
* @example | ||
* ```ts | ||
* import { Boolean } from "hkt-toolbelt"; | ||
* | ||
* const result = Boolean.and(true)(false) | ||
* // ^? false | ||
* ``` | ||
*/ | ||
export const and = ((a: boolean) => (b: boolean) => a && b) as Kind._$reify<And> |
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
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
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,17 @@ | ||
import { $, Test, NaturalNumber } from '..' | ||
|
||
type Square_Spec = [ | ||
/** | ||
* Can square a natural number. | ||
*/ | ||
Test.Expect<$<NaturalNumber.Square, 42>, 1764>, | ||
|
||
/** | ||
* Squaring zero results in zero. | ||
*/ | ||
Test.Expect<$<NaturalNumber.Square, 0>, 0> | ||
] | ||
|
||
it('should square a natural number', () => { | ||
expect(NaturalNumber.square(42)).toBe(1764) | ||
}) |
Oops, something went wrong.