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
/** Micro Api for building type predicates */ | |
module TypePredicateApi { | |
export type TypePredicate<refined> = (val: any) => val is refined; | |
export type TypeOfTypePredicate<refiner> = refiner extends TypePredicate<infer refined> ? refined : never; | |
export type TypePredicateMap = { [propertyName: string]: TypePredicate<any> } | |
export type ObjectFromTypePredicateMap<map extends { [propertyName: string]: TypePredicate<any> }> = { | |
[propertyName in keyof map]: TypeOfTypePredicate<map[propertyName]>; | |
} | |
/** Create a predicate which tests for an object. */ |
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
/** | |
* Imagine a Fluent Builder where some subset of the fluent methods are valid to call | |
* * after one or more fluent methods have been called | |
* * before one or more fluent methods have been called | |
* * limited number of times. | |
* | |
* There is no way to enforce such constraints in statically typed languages such as C++, C# or Java when using a single builder | |
* class/interface. Developers would need to author many interfaces to represent the different shapes and would likely need to | |
* author many versions of the builder itself (proxies with a specific signature delegating to an underlying source builder). | |
* |
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
/** | |
* When implementing the evaluation of a tree of expressions, an environment/context/memory representation is typically passed as an | |
* argument (or injected into the constructor of the interpreter class for OO realizations of the pattern) in order to give the | |
* expressions access to a memory store. | |
* | |
* The *Type* of the memory does not normally relate to any specific constructed expression ex. the memory may be implemented as an | |
* _arbitrary_ dictionary of key/value pairs. As such, there is no way to know if a type or instance of a dictionary of values can | |
* satisfy the needs to a specific constructed expression. | |
* | |
* For example, the following expression reads a number named 'x' from the environment and therefore the expression _requires_ an x of type number |
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
/** | |
* _Explicitly declare modifications_ to an existing object type via a fluent interface which yields a mapping function | |
* from the original data type to the type derived from the modification commands. | |
* | |
* The value over authoring a simple mapping function directly | |
* * harder to make a mistake due to the explicit nature | |
* * easier to read. | |
* | |
* This is _not_ production quality code but rather a _proof of concept_ gist for applying conditional/mapped | |
* types to mapper generation. A real-world usage might involve also generating the type-guard function |
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
type zero = unit | |
type 'a succ = unit -> 'a | |
type 'a nat = | |
| Zero : zero nat | |
| Succ : 'a nat -> 'a succ nat | |
module type T = sig | |
type t | |
val v : t nat |
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
#requires -version 2.0 | |
[CmdletBinding()] | |
param ( | |
[parameter(Mandatory=$true)] | |
[ValidateScript({ Test-Path -Path $_ -PathType Leaf })] | |
[string] | |
$Path | |
) | |
$ErrorActionPreference = 'Stop' |