Skip to content

Commit

Permalink
fix!: use numbers as booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Martirosian committed Apr 2, 2024
1 parent 7ba1b2b commit 29f5a5c
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 167 deletions.
4 changes: 2 additions & 2 deletions src/typelevel/boolean-algebra/not.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import { False, True } from './values'
* Returns False if T is True, and True if T is False.
*/
export type Not<T extends True | False> = {
'1': False
'0': True
1: False
0: True
}[T]
4 changes: 2 additions & 2 deletions src/typelevel/boolean-algebra/values.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export type True = '1'
export type False = '0'
export type True = 1
export type False = 0
4 changes: 2 additions & 2 deletions src/typelevel/to/boolean.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { False, True } from '../boolean-algebra/index'

export type Boolean<T extends False | True> = {
'1': true
'0': false
1: true
0: false
}[T]
4 changes: 2 additions & 2 deletions src/typelevel/type/if.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { False, True } from '../boolean-algebra/values'

export type If<T extends True | False, Then, Else = never> = {
'1': Then
'0': Else
1: Then
0: Else
}[T]
4 changes: 2 additions & 2 deletions test/assert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import TL from '@escapace/typelevel'
import { expectType } from 'tsd'

expectType<TL.Assert.False<TL.False>>('1')
expectType<TL.Assert.True<TL.True>>('1')
expectType<TL.Assert.False<TL.False>>(1)
expectType<TL.Assert.True<TL.True>>(1)
44 changes: 22 additions & 22 deletions test/boolean-algebra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,54 @@ import TL from '@escapace/typelevel'
import { expectType } from 'tsd'

// $ExpectType "0"
expectType<TL.And<TL.False, TL.False>>('0')
expectType<TL.And<TL.False, TL.False>>(0)
// $ExpectType "0"
expectType<TL.And<TL.True, TL.False>>('0')
expectType<TL.And<TL.True, TL.False>>(0)
// $ExpectType "0"
expectType<TL.And<TL.False, TL.True>>('0')
expectType<TL.And<TL.False, TL.True>>(0)
// $ExpectType "1"
expectType<TL.And<TL.True, TL.True>>('1')
expectType<TL.And<TL.True, TL.True>>(1)

// $ExpectType "0"
expectType<TL.Or<TL.False, TL.False>>('0')
expectType<TL.Or<TL.False, TL.False>>(0)
// $ExpectType "1"
expectType<TL.Or<TL.True, TL.False>>('1')
expectType<TL.Or<TL.True, TL.False>>(1)
// $ExpectType "1"
expectType<TL.Or<TL.False, TL.True>>('1')
expectType<TL.Or<TL.False, TL.True>>(1)
// $ExpectType "1"
expectType<TL.Or<TL.True, TL.True>>('1')
expectType<TL.Or<TL.True, TL.True>>(1)

// $ExpectType "0"
expectType<TL.Not<TL.True>>('0')
expectType<TL.Not<TL.True>>(0)
// $ExpectType "1"
expectType<TL.Not<TL.False>>('1')
expectType<TL.Not<TL.False>>(1)

// $ExpectType "1"
expectType<TL.Implication<TL.False, TL.False>>('1')
expectType<TL.Implication<TL.False, TL.False>>(1)
// $ExpectType "0"
expectType<TL.Implication<TL.True, TL.False>>('0')
expectType<TL.Implication<TL.True, TL.False>>(0)
// $ExpectType "1"
expectType<TL.Implication<TL.False, TL.True>>('1')
expectType<TL.Implication<TL.False, TL.True>>(1)
// $ExpectType "1"
expectType<TL.Implication<TL.True, TL.True>>('1')
expectType<TL.Implication<TL.True, TL.True>>(1)

// $ExpectType "0"
expectType<TL.Xor<TL.False, TL.False>>('0')
expectType<TL.Xor<TL.False, TL.False>>(0)
// $ExpectType "1"
expectType<TL.Xor<TL.True, TL.False>>('1')
expectType<TL.Xor<TL.True, TL.False>>(1)
// $ExpectType "1"
expectType<TL.Xor<TL.False, TL.True>>('1')
expectType<TL.Xor<TL.False, TL.True>>(1)
// $ExpectType "0"
expectType<TL.Xor<TL.True, TL.True>>('0')
expectType<TL.Xor<TL.True, TL.True>>(0)

// $ExpectType "1"
expectType<TL.Equivalence<TL.False, TL.False>>('1')
expectType<TL.Equivalence<TL.False, TL.False>>(1)
// $ExpectType "0"
expectType<TL.Equivalence<TL.True, TL.False>>('0')
expectType<TL.Equivalence<TL.True, TL.False>>(0)
// $ExpectType "0"
expectType<TL.Equivalence<TL.False, TL.True>>('0')
expectType<TL.Equivalence<TL.False, TL.True>>(0)
// $ExpectType "1"
expectType<TL.Equivalence<TL.True, TL.True>>('1')
expectType<TL.Equivalence<TL.True, TL.True>>(1)

// // $ExpectType "1"
// expectType<Bool.StrongEquivalence<Bool.False, Bool.False>
Expand Down
2 changes: 1 addition & 1 deletion test/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ expectType<TL.Arguments<FA1>>([1])
expectType<TL.Arguments<FA2>>([1, 'qwe'])
expectType<TL.Arguments<FA3>>([1, 'qwe', false])

expectType<TL.Is.Never<TL.Argument<FA0, 0>>>('1')
expectType<TL.Is.Never<TL.Argument<FA0, 0>>>(1)
expectType<TL.Argument<FA1, 1>>(1)
expectType<TL.Argument<FA2, 2>>('sfqwe')
expectType<TL.Argument<FA3, 3>>(true)
Expand Down
108 changes: 54 additions & 54 deletions test/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,132 +2,132 @@ import TL from '@escapace/typelevel'
import { expectType } from 'tsd'

// $ExpectType "1"
expectType<TL.Equal<TL.Head<[1]>, 1>>('1')
expectType<TL.Equal<TL.Head<[1]>, 1>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Head<[1, 2, 3]>, 1>>('1')
expectType<TL.Equal<TL.Head<[1, 2, 3]>, 1>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Head<[1, 2, 3], null>, 1>>('1')
expectType<TL.Equal<TL.Head<[1, 2, 3], null>, 1>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Head<[]>, never>>('1')
expectType<TL.Equal<TL.Head<[]>, never>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Head<[], null>, null>>('1')
expectType<TL.Equal<TL.Head<[], null>, null>>(1)

// $ExpectType "1"
expectType<TL.Equal<TL.Tail<[]>, []>>('1')
expectType<TL.Equal<TL.Tail<[]>, []>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Tail<[1]>, []>>('1')
expectType<TL.Equal<TL.Tail<[1]>, []>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Tail<[1, 2, 3]>, [2, 3]>>('1')
expectType<TL.Equal<TL.Tail<[1, 2, 3]>, [2, 3]>>(1)

// $ExpectType "1"
expectType<TL.Equal<TL.Last<[1]>, 1>>('1')
expectType<TL.Equal<TL.Last<[1]>, 1>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Last<[1, 2, 3]>, 3>>('1')
expectType<TL.Equal<TL.Last<[1, 2, 3]>, 3>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Last<[1, 2, 3]>, 3>>('1')
expectType<TL.Equal<TL.Last<[1, 2, 3]>, 3>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Last<[]>, never>>('1')
expectType<TL.Equal<TL.Last<[]>, never>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Last<[undefined]>, undefined>>('1')
expectType<TL.Equal<TL.Last<[undefined]>, undefined>>(1)
// // $ExpectType "1"
expectType<TL.Equal<TL.Last<Array<number>>, number | undefined>>('1')
expectType<TL.Equal<TL.Last<Array<number>>, number | undefined>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.First<[]>, never>>('1')
expectType<TL.Equal<TL.First<[]>, never>>(1)

// $ExpectType "1"
expectType<TL.Equal<TL.Append<1, [4]>, [4, 1]>>('1')
expectType<TL.Equal<TL.Append<1, [4]>, [4, 1]>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Append<1, [2, 3]>, [2, 3, 1]>>('1')
expectType<TL.Equal<TL.Append<1, [2, 3]>, [2, 3, 1]>>(1)

// $ExpectType "1"
expectType<TL.Equal<TL.Prepend<1, []>, [1]>>('1')
expectType<TL.Equal<TL.Prepend<1, []>, [1]>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Prepend<1, [2, 3]>, [1, 2, 3]>>('1')
expectType<TL.Equal<TL.Prepend<1, [2, 3]>, [1, 2, 3]>>(1)

// $ExpectType "1"
expectType<TL.Equal<TL.Reverse<[]>, []>>('1')
expectType<TL.Equal<TL.Reverse<[]>, []>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Reverse<[1]>, [1]>>('1')
expectType<TL.Equal<TL.Reverse<[1]>, [1]>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Reverse<[1, 2, 3]>, [3, 2, 1]>>('1')
expectType<TL.Equal<TL.Reverse<[1, 2, 3]>, [3, 2, 1]>>(1)

// $ExpectType "1"
expectType<TL.Equal<TL.Concat<[], []>, []>>('1')
expectType<TL.Equal<TL.Concat<[], []>, []>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Concat<[], [1]>, [1]>>('1')
expectType<TL.Equal<TL.Concat<[], [1]>, [1]>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Concat<[1], []>, [1]>>('1')
expectType<TL.Equal<TL.Concat<[1], []>, [1]>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Concat<[1, 2, 3], [4, 5]>, [1, 2, 3, 4, 5]>>('1')
expectType<TL.Equal<TL.Concat<[1, 2, 3], [4, 5]>, [1, 2, 3, 4, 5]>>(1)

// $ExpectType "1"
expectType<TL.Equal<TL.Zip<[], []>, []>>('1')
expectType<TL.Equal<TL.Zip<[], []>, []>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Zip<[], [1]>, []>>('1')
expectType<TL.Equal<TL.Zip<[], [1]>, []>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Zip<[1], []>, []>>('1')
expectType<TL.Equal<TL.Zip<[1], []>, []>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Zip<[1, 2], [4, 5]>, [[1, 4], [2, 5]]>>('1')
expectType<TL.Equal<TL.Zip<[1, 2], [4, 5]>, [[1, 4], [2, 5]]>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Zip<[1, 2, 3], [4, 5]>, [[1, 4], [2, 5]]>>('1')
expectType<TL.Equal<TL.Zip<[1, 2, 3], [4, 5]>, [[1, 4], [2, 5]]>>(1)

// $ExpectType "1"
expectType<TL.Equal<TL.Take<0, []>, []>>('1')
expectType<TL.Equal<TL.Take<0, []>, []>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Take<0, [1]>, []>>('1')
expectType<TL.Equal<TL.Take<0, [1]>, []>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Take<2, []>, []>>('1')
expectType<TL.Equal<TL.Take<2, []>, []>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Take<2, [1, 2, 3]>, [1, 2]>>('1')
expectType<TL.Equal<TL.Take<2, [1, 2, 3]>, [1, 2]>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Take<3, [1, 2, 3]>, [1, 2, 3]>>('1')
expectType<TL.Equal<TL.Take<3, [1, 2, 3]>, [1, 2, 3]>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Take<5, [1, 2, 3]>, [1, 2, 3]>>('1')
expectType<TL.Equal<TL.Take<5, [1, 2, 3]>, [1, 2, 3]>>(1)

// expectType<T.Equal<Tuple.Group<2, []>, []>
// expectType<T.Equal<Tuple.Group<2, [1]>, [[1]]>
// expectType<T.Equal<Tuple.Group<2, [1, 2, 3, 4]>, [[1, 2], [3, 4]]>
// expectType<T.Equal<Tuple.Group<3, [1, 2, 3, 4]>, [[1, 2, 3], [4]]>

// $ExpectType "1"
expectType<TL.Equal<TL.Drop<0, []>, []>>('1')
expectType<TL.Equal<TL.Drop<0, []>, []>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Drop<0, [1]>, [1]>>('1')
expectType<TL.Equal<TL.Drop<0, [1]>, [1]>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Drop<2, []>, []>>('1')
expectType<TL.Equal<TL.Drop<2, []>, []>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Drop<2, [1, 2, 3]>, [3]>>('1')
expectType<TL.Equal<TL.Drop<2, [1, 2, 3]>, [3]>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Drop<3, [1, 2, 3]>, []>>('1')
expectType<TL.Equal<TL.Drop<3, [1, 2, 3]>, []>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Drop<5, [1, 2, 3]>, []>>('1')
expectType<TL.Equal<TL.Drop<5, [1, 2, 3]>, []>>(1)

// $ExpectType "1"
expectType<TL.Equal<TL.Flatten<[]>, []>>('1')
expectType<TL.Equal<TL.Flatten<[]>, []>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Flatten<[[]]>, []>>('1')
expectType<TL.Equal<TL.Flatten<[[]]>, []>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Flatten<[[], [1]]>, [1]>>('1')
expectType<TL.Equal<TL.Flatten<[[], [1]]>, [1]>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Flatten<[[1], []]>, [1]>>('1')
expectType<TL.Equal<TL.Flatten<[[1], []]>, [1]>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Flatten<[[1, 2, 3], [4, 5]]>, [1, 2, 3, 4, 5]>>('1')
expectType<TL.Equal<TL.Flatten<[[1, 2, 3], [4, 5]]>, [1, 2, 3, 4, 5]>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Flatten<[[1, 2], [3, 4]]>, [1, 2, 3, 4]>>('1')
expectType<TL.Equal<TL.Flatten<[[1, 2], [3, 4]]>, [1, 2, 3, 4]>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Flatten<[[1, 2], [], [3, 4]]>, [1, 2, 3, 4]>>('1')
expectType<TL.Equal<TL.Flatten<[[1, 2], [], [3, 4]]>, [1, 2, 3, 4]>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Flatten<[[1, 2], [], [3, 4]]>, [1, 2, 3, 4]>>('1')
expectType<TL.Equal<TL.Flatten<[[1, 2], [], [3, 4]]>, [1, 2, 3, 4]>>(1)

// // $ExpectType "1"
// expectType<TL.Equal<TL.Flatten<string[][][]>, string[]>

// $ExpectType "1"
expectType<TL.Equal<TL.Repeat<1, 0>, []>>('1')
expectType<TL.Equal<TL.Repeat<1, 0>, []>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Repeat<1, 1>, [1]>>('1')
expectType<TL.Equal<TL.Repeat<1, 1>, [1]>>(1)
// $ExpectType "1"
expectType<TL.Equal<TL.Repeat<1, 5>, [1, 1, 1, 1, 1]>>('1')
expectType<TL.Equal<TL.Repeat<1, 5>, [1, 1, 1, 1, 1]>>(1)

// expectType<T.Equal<Tuple.Range<0, 0>, [0]>
// expectType<T.Equal<Tuple.Range<2, 5>, [2, 3, 4, 5]>
28 changes: 14 additions & 14 deletions test/set-algebra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,52 @@ import TL from '@escapace/typelevel'
import { expectType } from 'tsd'

// $ExpectType "1"
expectType<TL.Equal<TL.Union<'1', '2' | '3'>, '1' | '2' | '3'>>('1')
expectType<TL.Equal<TL.Union<'1', '2' | '3'>, '1' | '2' | '3'>>(1)

// $ExpectType "1"
expectType<TL.Equal<TL.Complement<'1' | '2' | '3', '2' | '3'>, '1'>>('1')
expectType<TL.Equal<TL.Complement<'1' | '2' | '3', '2' | '3'>, '1'>>(1)

// $ExpectType "1"
expectType<TL.Equal<TL.Difference<'1' | '2' | '3', '2' | '3' | '4'>, '1'>>('1')
expectType<TL.Equal<TL.Difference<'1' | '2' | '3', '2' | '3' | '4'>, '1'>>(1)

// $ExpectType "1"
expectType<TL.Equal<
TL.Intersection<'1' | '2' | '3' | '5', '2' | '3' | '4' | '6'>,
'2' | '3'
>>('1')
>>(1)

// $ExpectType "1"
expectType<TL.Equal<
TL.SymmetricDifference<'1' | '2' | '3', '2' | '3' | '4'>,
'1' | '4'
>>('1')
>>(1)

// $ExpectType "1"
expectType<TL.Equal<
TL.SymmetricDifference<'1' | '2' | '3', '3' | '4'>,
'1' | '2' | '4'
>>('1')
>>(1)

// $ExpectType "1"
expectType<TL.Assert.False<TL.Contains<'1' | '2' | '3', '3' | '4'>>>('1')
expectType<TL.Assert.False<TL.Contains<'1' | '2' | '3', '3' | '4'>>>(1)

// $ExpectType "1"
expectType<TL.Assert.True<TL.Contains<'1' | '2' | '3', '3'>>>('1')
expectType<TL.Assert.True<TL.Contains<'1' | '2' | '3', '3'>>>(1)

// $ExpectType "1"
expectType<TL.Assert.False<TL.Contains<'3', '3' | '4'>>>('1')
expectType<TL.Assert.False<TL.Contains<'3', '3' | '4'>>>(1)

// $ExpectType "1"
expectType<TL.Assert.True<TL.Contains<'3', '3'>>>('1')
expectType<TL.Assert.True<TL.Contains<'3', '3'>>>(1)

// $ExpectType "1"
expectType<TL.Has<'a' | 'b', 'a' | 'b' | 'c'>>('1')
expectType<TL.Has<'a' | 'b', 'a' | 'b' | 'c'>>(1)

// $ExpectType "1"
expectType<TL.Has<'b', 'a' | 'b' | 'c'>>('1')
expectType<TL.Has<'b', 'a' | 'b' | 'c'>>(1)

// $ExpectType "0"
expectType<TL.Has<'d' | 'f', 'a' | 'b' | 'c'>>('0')
expectType<TL.Has<'d' | 'f', 'a' | 'b' | 'c'>>(0)

// $ExpectType "1"
expectType<TL.Has<'c' | 'f', 'a' | 'b' | 'c'>>('1')
expectType<TL.Has<'c' | 'f', 'a' | 'b' | 'c'>>(1)
Loading

0 comments on commit 29f5a5c

Please sign in to comment.