This repository has been archived by the owner on Feb 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add create-various-curried-function-types
- Loading branch information
Showing
10 changed files
with
450 additions
and
22 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
55 changes: 55 additions & 0 deletions
55
src/advanced/__tests__/__snapshots__/create-various-curried-function-types.ts.snap
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,55 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should return correctly 1`] = ` | ||
"type map = map_00; | ||
type map_00 = { | ||
<T>(_fn: PH, mappable: Mappable<T>): map_mappable_01<T>; | ||
<T>(_fn: PH, array: T[]): map_array_01<T>; | ||
<T, U>(fn: (v: T) => U, array: T[]): map_array_11<T, U>; | ||
<T, U>(fn: (v: T) => U, mappable: Mappable<T>): map_mappable_11<T, U>; | ||
<K extends \\"array\\", X extends \\"01\\">(): <T>(_fn: PH, array: T[]) => map_array_01<T>; | ||
<K extends \\"mappable\\">(): map_mappable_00; | ||
<X extends \\"1\\">(): <T, U>(fn: (v: T) => U) => map_10<T, U>; | ||
<K extends \\"array\\">(): map_array_00; | ||
<K extends \\"array\\", X extends \\"11\\">(): <T, U>(fn: (v: T) => U, array: T[]) => map_array_11<T, U>; | ||
<K extends \\"mappable\\", X extends \\"11\\">(): <T, U>(fn: (v: T) => U, mappable: Mappable<T>) => map_mappable_11<T, U>; | ||
<K extends \\"mappable\\", X extends \\"01\\">(): <T>(_fn: PH, mappable: Mappable<T>) => map_mappable_01<T>; | ||
<T, U>(fn: (v: T) => U): map_10<T, U>; | ||
}; | ||
type map_10 = { | ||
(array: T[]): map_array_11<T, U>; | ||
<K extends \\"array\\">(): (array: T[]) => map_array_11<T, U>; | ||
<K extends \\"mappable\\">(): (mappable: Mappable<T>) => map_mappable_11<T, U>; | ||
(mappable: Mappable<T>): map_mappable_11<T, U>; | ||
}; | ||
type map_array_00 = { | ||
<T>(_fn: PH, array: T[]): map_array_01<T>; | ||
<T, U>(fn: (v: T) => U, array: T[]): map_array_11<T, U>; | ||
<X extends \\"11\\">(): <T, U>(fn: (v: T) => U, array: T[]) => map_array_11<T, U>; | ||
<X extends \\"01\\">(): <T>(_fn: PH, array: T[]) => map_array_01<T>; | ||
<X extends \\"1\\">(): <T, U>(fn: (v: T) => U) => map_array_10<T, U>; | ||
<T, U>(fn: (v: T) => U): map_array_10<T, U>; | ||
}; | ||
type map_array_01<T> = { | ||
<U>(fn: (v: T) => U): map_array_11<T, U>; | ||
}; | ||
type map_array_10<T, U> = { | ||
(array: T[]): map_array_11<T, U>; | ||
}; | ||
type map_array_11<T, U> = U[]; | ||
type map_mappable_00 = { | ||
<T>(_fn: PH, mappable: Mappable<T>): map_mappable_01<T>; | ||
<T, U>(fn: (v: T) => U, mappable: Mappable<T>): map_mappable_11<T, U>; | ||
<X extends \\"11\\">(): <T, U>(fn: (v: T) => U, mappable: Mappable<T>) => map_mappable_11<T, U>; | ||
<X extends \\"01\\">(): <T>(_fn: PH, mappable: Mappable<T>) => map_mappable_01<T>; | ||
<X extends \\"1\\">(): <T, U>(fn: (v: T) => U) => map_mappable_10<T, U>; | ||
<T, U>(fn: (v: T) => U): map_mappable_10<T, U>; | ||
}; | ||
type map_mappable_01<T> = { | ||
<U>(fn: (v: T) => U): map_mappable_11<T, U>; | ||
}; | ||
type map_mappable_10<T, U> = { | ||
(mappable: Mappable<T>): map_mappable_11<T, U>; | ||
}; | ||
type map_mappable_11<T, U> = Mappable<U>;" | ||
`; |
55 changes: 55 additions & 0 deletions
55
src/advanced/__tests__/create-various-curried-function-types.ts
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,55 @@ | ||
jest.disableAutomock(); | ||
|
||
import {TypeDeclaration} from '../../elements/declarations/type-declaration'; | ||
import {Document} from '../../elements/document'; | ||
import {Parameter} from '../../elements/parameter'; | ||
import {ArrayType} from '../../elements/types/array-type'; | ||
import {BasicType} from '../../elements/types/basic-type'; | ||
import {FunctionType} from '../../elements/types/function-type'; | ||
import {GenericType} from '../../elements/types/generic-type'; | ||
import {TypedType} from '../../elements/types/typed-type'; | ||
import {create_various_curried_function_types} from '../create-various-curried-function-types'; | ||
|
||
const name = 'map'; | ||
const generic_T = new GenericType({name: 'T'}); | ||
const generic_U = new GenericType({name: 'U'}); | ||
const parameter_fn = new Parameter({ | ||
name: 'fn', | ||
type: new FunctionType({ | ||
parameters: [new Parameter({name: 'v', type: generic_T})], | ||
return: generic_U, | ||
}), | ||
}); | ||
|
||
const function_type_array = new FunctionType({ | ||
generics: [generic_T, generic_U], | ||
parameters: [ | ||
parameter_fn, | ||
new Parameter({name: 'array', type: new ArrayType({owned: generic_T})}), | ||
], | ||
return: new ArrayType({owned: generic_U}), | ||
}); | ||
|
||
const mappable = new TypeDeclaration({name: 'Mappable'}); | ||
const function_type_mappable = new FunctionType({ | ||
generics: [generic_T, generic_U], | ||
parameters: [ | ||
parameter_fn, | ||
new Parameter({name: 'mappable', type: new TypedType({owned: mappable, generics: [generic_T]})}), | ||
], | ||
return: new TypedType({owned: mappable, generics: [generic_U]}), | ||
}); | ||
|
||
it('should return correctly', () => { | ||
const types = create_various_curried_function_types({ | ||
name, | ||
types: { | ||
array: function_type_array, | ||
mappable: function_type_mappable, | ||
}, | ||
selectable: true, | ||
placeholder: new BasicType({name: 'PH'}), | ||
}); | ||
const document = new Document({children: types}); | ||
expect(document.emit()).toMatchSnapshot(); | ||
}); |
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
Oops, something went wrong.