-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Morph interface, unified mapping for nested arrays, generic types
- Loading branch information
Showing
7 changed files
with
238 additions
and
104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
import MorphOne from '@/MorphOne' | ||
import type { ArrayElement } from '../types/scaffolding' | ||
import type { Morph } from '../types' | ||
|
||
export default class MorphEach { | ||
private readonly _morph: MorphOne | ||
export default class MorphEach< | ||
Source extends unknown[] = unknown[], | ||
Target extends unknown[] = unknown[] | ||
> implements Morph<Source, Target> { | ||
private readonly _morph: Morph< | ||
ArrayElement<Source>, | ||
ArrayElement<Target> | ||
> | ||
|
||
constructor (morph: MorphOne) { | ||
constructor (morph: Morph< | ||
ArrayElement<Source>, | ||
ArrayElement<Target> | ||
>) { | ||
this._morph = morph | ||
} | ||
|
||
apply (source: unknown[]): unknown[] { | ||
return source.map(v => this._morph.apply(v)) | ||
convert (source: Source): Target { | ||
return source.map(v => this._morph.convert(v as ArrayElement<Source>)) as Target | ||
} | ||
} |
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
Oops, something went wrong.