commit 24bbc494310a93c7e7136347117bdfe491c96478
parent 2821428fcf3a45cd1a3765014bcd77d9d9291c28
Author: AlexKnauth <alexander@knauth.org>
Date: Wed, 29 Jul 2015 00:38:29 -0400
document mapper.rkt
Diffstat:
3 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/kw-utils/docs/kw-utils.scrbl b/kw-utils/docs/kw-utils.scrbl
@@ -12,3 +12,4 @@ source code: @url["https://github.com/AlexKnauth/kw-utils"]
@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")]
+@include-section[(lib "kw-utils/docs/mapper.scrbl")]
diff --git a/kw-utils/docs/mapper.scrbl b/kw-utils/docs/mapper.scrbl
@@ -0,0 +1,30 @@
+#lang scribble/manual
+
+@(require scribble/eval
+ (for-label kw-utils/mapper
+ kw-utils/partial
+ kw-utils/kw-map
+ (except-in racket/base map)
+ racket/contract/base
+ racket/function
+ ))
+
+@title{Creating functions that map over lists}
+
+@defmodule[kw-utils/mapper]
+
+@defproc*[([(mapper [f procedure?] [arg any/c] ... [#:<kw> kw-arg any/c] ...) procedure?]
+ [(mapper [#:<kw> kw-arg any/c] ...) procedure?])]{
+The one-argument case is equivalent to a curried version of @racket[map].
+
+@racket[(mapper f)] is equivalent to @racket[(partial map f)], and
+@racket[(mapper arg ...)] is equivalent to
+@racket[(partial map (partial arg ...))].
+@examples[
+ (require kw-utils/mapper)
+ ((mapper add1) '(1 2 3))
+ ((mapper +) '(1 2 3) '(4 5 6))
+ ((mapper + 3) '(1 2 3))
+ ((mapper + 3) '(1 2 3) '(4 5 6))
+]}
+
diff --git a/kw-utils/mapper.rkt b/kw-utils/mapper.rkt
@@ -15,7 +15,9 @@ define mapper
module+ test
check-equal? ((mapper add1) '(1 2 3)) '(2 3 4)
check-equal? ((mapper +) '(1 2 3) '(4 5 6)) '(5 7 9)
+ check-equal? ((mapper + 3) '(1 2 3)) '(4 5 6)
check-equal? ((mapper + 3) '(1 2 3) '(4 5 6)) '(8 10 12)
check-equal? ((mapper app + 3) '(1 2 3) '(4 5 6)) '(8 10 12)
+ check-equal? ((mapper app) (list add1 sub1) '(0 0)) '(1 -1)
check-equal? ((mapper) (list add1 sub1) '(0 0)) '(1 -1)