-
-
Save mark-jay/e5b55286635affb2a99c to your computer and use it in GitHub Desktop.
Partial application in Bash
This file contains hidden or 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
| function curry() { | |
| exportfun=$1; shift | |
| fun=$1; shift | |
| params=$* | |
| cmd=$"function $exportfun() { | |
| more_params=\$*; | |
| $fun $params \$more_params; | |
| }" | |
| eval $cmd | |
| } | |
| function add() { | |
| a=$1; shift | |
| b=$1; shift | |
| expr $a + $b | |
| } | |
| curry add3 add 3 | |
| $add3 9 | |
| # Guess the output :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment