-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add API for partially config Amplify
- Loading branch information
Di Wu
committed
Nov 3, 2023
1 parent
7a5440a
commit 0191532
Showing
3 changed files
with
123 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
type Getter<W, P> = (w: W) => P; | ||
type Setter<W, P> = (p: P) => (w: W) => W; | ||
|
||
export class Lens<W, P> { | ||
private readonly get: Getter<W, P>; | ||
|
||
/** @internal */ | ||
readonly set: Setter<W, P>; | ||
|
||
static of<T>(): Lens<T, T> { | ||
return new Lens<T, T>( | ||
t => t, | ||
t => () => t | ||
); | ||
} | ||
|
||
constructor(get: Getter<W, P>, set: Setter<W, P>) { | ||
this.get = get; | ||
this.set = set; | ||
} | ||
|
||
atKey<Q extends keyof P>(key: Q): Lens<W, P[Q]> { | ||
return new Lens<W, P[Q]>( | ||
w => this.get(w)[key], | ||
pq => w => | ||
this.set({ | ||
...this.get(w), | ||
[key]: pq, | ||
})(w) | ||
); | ||
} | ||
} |