Skip to content

Latest commit

 

History

History
 
 

README.md

This directory and it's subdirectories contain syntax changes that enable common programming scenarios in PowerShell and PipeScript.

DisplayName Synopsis
NamespacedFunction Namespaced functions
ArrowOperator Arrow Operator
ConditionalKeyword Conditional Keyword Expansion

NamespacedFunction Example 1

    {
        abstract function Point {
            param(
            [Alias('Left')]
            [vbn()]
            $X,

            [Alias('Top')]
            [vbn()]
            $Y
            )
        }
    }.Transpile()

NamespacedFunction Example 2

    {
        interface function AccessToken {
            param(
            [Parameter(ValueFromPipelineByPropertyName)]
            [Alias('Bearer','PersonalAccessToken', 'PAT')]
            [string]
            $AccessToken
            )
        }
    }.Transpile()

NamespacedFunction Example 3

    {
        partial function PartialExample {
            process {
                1
            }
        }

        partial function PartialExample* {
            process {
                2
            }
        }

        partial function PartialExample// {
            process {
                3
            }
        }        

        function PartialExample {
            
        }
    }.Transpile()

ArrowOperator Example 1

    $allTypes = 
        Invoke-PipeScript {
            [AppDomain]::CurrentDomain.GetAssemblies() => $_.GetTypes()
        }

    $allTypes.Count # Should -BeGreaterThan 1kb
    $allTypes # Should -BeOfType ([Type])

ArrowOperator Example 2

    Invoke-PipeScript {
        Get-Process -ID $PID => ($Name, $Id, $StartTime) => { "$Name [$ID] $StartTime"}
    } # Should -Match "$pid"

ArrowOperator Example 3

    Invoke-PipeScript {
        func => ($Name, $Id) { $Name, $Id}
    } # Should -BeOfType ([ScriptBlock])

ConditionalKeyword Example 1

    Invoke-PipeScript {
        $n = 1
        do {
            $n = $n * 2
            $n
            break if (-not ($n % 16))
        } while ($true)
    }

ConditionalKeyword Example 2

    Import-PipeScript {
        
        function Get-Primes([ValidateRange(2,64kb)][int]$UpTo) {
            $KnownPrimes = new Collections.ArrayList @(2)
            $SieveOfEratosthenes = new Collections.Generic.Dictionary[uint32,bool]            
            $n = 2
            :nextNumber for (; $n++;) {             
                # Break if past our point of interest
                break if ($n -ge $upTo)
                # Skip if an even number
                continue if (-not ($n -band 1))
                # Check our sieve
                continue if $SieveOfEratosthenes.ContainsKey($n)
                # Determine half of the number
                $halfN = $n /2
                # If this is divisible by the known primes
                foreach ($k in $knownPrimes) {
                    continue nextNumber if (($n % $k) -eq 0) {}
                    break if ($k -ge $halfN)
                }                
                foreach ($k in $knownPrimes) {
                    $SieveOfEratosthenes[$n * $k] = $true                
                }
                $null = $knownPrimes.Add($n)
            }
            $knownPrimes -le $UpTo
        }
    }