Allow aliases to bind parameters to enable function Currying - by rerun

Status : 

 


5
0
Sign in
to vote
ID 798778 Comments
Status Active Workarounds
Type Suggestion Repros 0
Opened 8/28/2013 10:42:28 AM
Access Restriction Public

Description

I have created several powershell modules for enterprise system and the number of parameters commands need to support is always at odds with making them easy to use.  Often I find myself creating helper functions that just bind parameters to other functions.  If the new-alias command allow users to create new alias that already set some options simplified versions use cases could be provided.

An example would be if I wanted to curry get-childitem so that it searches files only 
It would be nice if I could do the following 

<code>
>Set-Alias getfiles -Value "Get-ChildItem -File"
>getfiles -r -filter foo
</code>

This can be simulated using the following idiom but the user loses all the power of the cmdlets and supporting the many possible parameter sets is unworkable.

<code>
function getfilesfn($filter = "*"){Get-ChildItem -Filter $filter}
getfilesfn get*
</code>

If we were able to curry cmdlets whole apis could be developed using aliases alone.
Sign in to post a comment.