commit 2821428fcf3a45cd1a3765014bcd77d9d9291c28
parent bef3f896e8cc7720ff93581d9b3ef6d82d661765
Author: AlexKnauth <alexander@knauth.org>
Date: Wed, 29 Jul 2015 00:24:56 -0400
document partial.rkt
Diffstat:
2 files changed, 52 insertions(+), 5 deletions(-)
diff --git a/kw-utils/docs/kw-utils.scrbl b/kw-utils/docs/kw-utils.scrbl
@@ -7,12 +7,8 @@ source code: @url["https://github.com/AlexKnauth/kw-utils"]
@local-table-of-contents[]
@include-section[(lib "kw-utils/docs/keyword-lambda.scrbl")]
-
@include-section[(lib "kw-utils/docs/keyword-apply-sort.scrbl")]
-
@include-section[(lib "kw-utils/docs/arity+keywords.scrbl")]
-
@include-section[(lib "kw-utils/docs/kw-map.scrbl")]
-
@include-section[(lib "kw-utils/docs/kw-hash.scrbl")]
-
+@include-section[(lib "kw-utils/docs/partial.scrbl")]
diff --git a/kw-utils/docs/partial.scrbl b/kw-utils/docs/partial.scrbl
@@ -0,0 +1,51 @@
+#lang scribble/manual
+
+@(require scribble/eval
+ (for-label kw-utils/partial
+ racket/base
+ racket/contract/base
+ racket/function
+ ))
+
+@title{Partial application with keywords}
+
+@defmodule[kw-utils/partial]
+
+@defproc*[([(partial [f procedure?] [arg any/c] ... [#:<kw> kw-arg any/c] ...) procedure?]
+ [(partial [#:<kw> kw-arg any/c] ...) procedure?])]{
+Similar to @racket[curry], but better thought of as a generalization of
+@racketidfont{partial} from @racketmodname[rackjure]. Unlike @racket[curry],
+(but like the @racketmodname[rackjure] version), it does not care about function
+arity, and so has much simpler behavior, so that
+@racket[((partial f in-arg ...) out-arg ...)] is equivalent to
+@racket[(f in-arg ... out-arg ...)] no matter what arity @racket[f] has.
+It also generalizes this idea to include keyword arguments.
+@examples[
+ (require kw-utils/partial)
+ ((partial + 1 2))
+ ((partial + 1) 2)
+ ((partial +) 1 2)
+ ((partial) + 1 2)
+ (define (KE #:m m #:v v)
+ (* 1/2 m v v))
+ ((partial KE) #:m 2 #:v 1)
+ ((partial KE #:m 2) #:v 1)
+ ((partial KE #:m 2 #:v 1))
+ ((partial) KE #:m 2 #:v 1)
+ ((partial #:m 2) KE #:v 1)
+]}
+
+@defproc[(app [f procedure?] [arg any/c] ... [#:<kw> kw-arg any/c] ...) any]{
+A procedure for normal function application.
+@racket[(partial #:<kw> kw-arg ... ...)] is equivalent to
+@racket[(partial app #:<kw> kw-arg ... ...)].
+@examples[
+ (require kw-utils/partial)
+ (+ 1 2)
+ (app + 1 2)
+ (define (KE #:m m #:v v)
+ (* 1/2 m v v))
+ (KE #:m 2 #:v 1)
+ (app KE #:m 2 #:v 1)
+]}
+