Permalink
Browse files

better variadic examples

  • Loading branch information...
1 parent f5f1704 commit fd59f2fcb7d417bd0fad6d75959af3006a8ec096 @raganwald raganwald committed Jan 6, 2013
Showing with 14 additions and 4 deletions.
  1. +14 −4 2013/01/practical-applications-of-partial-application.md
@@ -71,15 +71,25 @@ function ellipsis (fn) {
var variadic = ellipsis;
-function I (something) {
- return something
+function unary (first) {
+ return first
}
-I('why', 'hello', 'there')
+unary('why', 'hello', 'there')
//=> 'why'
-variadic(I)('why', 'hello', 'there')
+variadic(unary)('why', 'hello', 'there')
//=> [ 'why', 'hello', 'there' ]
+
+function binary (first, rest) {
+ return [first, rest]
+}
+
+binary('why', 'hello', 'there')
+ //=> [ 'why', 'hello' ]
+
+variadic(binary)('why', 'hello', 'there')
+ //=> [ 'why', [ 'hello', 'there' ] ]
```
Variadic is a *function decorator*, it "decorates" a function with some additional functionality while remaining true to its underlying purpose.

0 comments on commit fd59f2f

Please sign in to comment.