Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dalen/puppet-defn
Puppet function to define Puppet functions in Puppet
https://github.com/dalen/puppet-defn
Last synced: 21 days ago
JSON representation
Puppet function to define Puppet functions in Puppet
- Host: GitHub
- URL: https://github.com/dalen/puppet-defn
- Owner: dalen
- Created: 2014-01-30T20:57:21.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-10-28T12:08:00.000Z (about 10 years ago)
- Last Synced: 2024-10-26T19:25:32.352Z (25 days ago)
- Language: Ruby
- Size: 152 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
A Puppet function to define Puppet functions in Puppet
======================================================Requires the future parser to work.
Example:
--------defn(higher) |$a,$b| { if $a > $b { $a } else { $b } }
notice(higher(3,2))*Output:* 3
Quicksort example:
------------------```puppet
class quicksort {
$size=lambda() |$list| {
reduce($list,0) |$a,$b| {
$a+1
}
}
$sort=lambda() |$list| {
if apply($size,[$list]) > 2 {
$pivot=$list[apply($size,[$list])/2]
apply($sort,[filter($list) |$i| { $i < $pivot }]) + $same + apply($sort,[])
$low=filter($list) |$i| {
$i < $pivot
}
$high=filter($list) |$i| {
$i > $pivot
}
$same=filter($list) |$i| {
$i == $pivot
}
} elsif apply($size,[$list]) == 2 {
if $list[0] > $list[1] {
[$list[1], $list[0]]
} else {
$list
}
} else {
$list
}
}
}include quicksort
apply($quicksort::sort, [[3,7,4,8,6]]).each |$i| { notice($i) }
```Known issues
------------Nesting defn statements or referencing variables from outside of the block can
lead to undefined behaviour.Also closures aren't supported by Puppet with lambdas.