-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow nested concrete ClarityValue types to be specified
- Loading branch information
Showing
8 changed files
with
183 additions
and
43 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
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,24 +1,30 @@ | ||
import { ClarityType, ClarityValue } from '../clarityValue'; | ||
|
||
type OptionalCV = NoneCV | SomeCV; | ||
type OptionalCV<T extends ClarityValue = ClarityValue> = NoneCV | SomeCV<T>; | ||
|
||
interface NoneCV { | ||
readonly type: ClarityType.OptionalNone; | ||
} | ||
|
||
interface SomeCV { | ||
interface SomeCV<T extends ClarityValue = ClarityValue> { | ||
readonly type: ClarityType.OptionalSome; | ||
readonly value: ClarityValue; | ||
readonly value: T; | ||
} | ||
|
||
const noneCV = (): OptionalCV => ({ type: ClarityType.OptionalNone }); | ||
const someCV = (value: ClarityValue): OptionalCV => ({ type: ClarityType.OptionalSome, value }); | ||
const optionalCVOf = (value?: ClarityValue): OptionalCV => { | ||
function noneCV(): NoneCV { | ||
return { type: ClarityType.OptionalNone }; | ||
} | ||
|
||
function someCV<T extends ClarityValue = ClarityValue>(value: T): OptionalCV<T> { | ||
return { type: ClarityType.OptionalSome, value }; | ||
} | ||
|
||
function optionalCVOf<T extends ClarityValue = ClarityValue>(value?: T): OptionalCV<T> { | ||
if (value) { | ||
return someCV(value); | ||
} else { | ||
return noneCV(); | ||
} | ||
}; | ||
} | ||
|
||
export { OptionalCV, NoneCV, SomeCV, noneCV, someCV, optionalCVOf }; |
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
da68307
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: