On this page:
4.1 Map with keyword arguments
map
4.2 Partial application with keywords
partial
app
4.3 Creating functions that map over lists
mapper
8.12

4 Higher Order Functions with Keywords🔗ℹ

4.1 Map with keyword arguments🔗ℹ

 (require kw-utils/kw-map) package: kw-utils

procedure

(map proc lst ... #:<kw> lst2 ...)  list?

  proc : procedure?
  lst : list?
  lst2 : list?
like map from racket/base, but accepts keyword arguments as well as positional arguments.

Examples:
> (require kw-utils/kw-map racket/math)
> (map (λ (x) (+ x 1)) '(1 2 3 4))

'(2 3 4 5)

> (map (λ (#:x x) (+ x 1)) #:x '(1 2 3 4))

'(2 3 4 5)

> (map (λ (x y) (+ x y)) '(1 2 3 4) '(10 100 1000 10000))

'(11 102 1003 10004)

> (map (λ (x #:y y) (+ x y)) '(1 2 3 4) #:y '(10 100 1000 10000))

'(11 102 1003 10004)

> (define (KE #:m m #:v v)
    (* 1/2 m (sqr v)))
> (map KE #:m '(2 2 2 2) #:v '(0 1 2 3))

'(0 1 4 9)

> (map KE #:m '(0 1 2 3) #:v '(0 1 2 3))

'(0 1/2 4 27/2)

> (map KE #:m '(1 2 1/2 2/9) #:v '(0 1 2 3))

'(0 1 1 1)

4.2 Partial application with keywords🔗ℹ

 (require kw-utils/partial) package: kw-utils

procedure

(partial f arg ... #:<kw> kw-arg ...)  procedure?

  f : procedure?
  arg : any/c
  kw-arg : any/c
(partial #:<kw> kw-arg ...)  procedure?
  kw-arg : any/c
Similar to curry, but better thought of as a generalization of partial from rackjure. Unlike curry, (but like the rackjure version), it does not care about function arity, and so has much simpler behavior, so that ((partial f in-arg ...) out-arg ...) is equivalent to (f in-arg ... out-arg ...) no matter what arity f has. It also generalizes this idea to include keyword arguments.

Examples:
> (require kw-utils/partial)
> ((partial + 1 2))

3

> ((partial + 1) 2)

3

> ((partial +) 1 2)

3

> ((partial) + 1 2)

3

> (define (KE #:m m #:v v)
    (* 1/2 m v v))
> ((partial KE) #:m 2 #:v 1)

1

> ((partial KE #:m 2) #:v 1)

1

> ((partial KE #:m 2 #:v 1))

1

> ((partial) KE #:m 2 #:v 1)

1

> ((partial #:m 2) KE #:v 1)

1

procedure

(app f arg ... #:<kw> kw-arg ...)  any

  f : procedure?
  arg : any/c
  kw-arg : any/c
A procedure for normal function application. (partial #:<kw> kw-arg ... ...) is equivalent to (partial app #:<kw> kw-arg ... ...).

Examples:
> (require kw-utils/partial)
> (+ 1 2)

3

> (app + 1 2)

3

> (define (KE #:m m #:v v)
    (* 1/2 m v v))
> (KE #:m 2 #:v 1)

1

> (app KE #:m 2 #:v 1)

1

4.3 Creating functions that map over lists🔗ℹ

 (require kw-utils/mapper) package: kw-utils

procedure

(mapper f arg ... #:<kw> kw-arg ...)  procedure?

  f : procedure?
  arg : any/c
  kw-arg : any/c
(mapper #:<kw> kw-arg ...)  procedure?
  kw-arg : any/c
The one-argument case is equivalent to a curried version of map.

(mapper f) is equivalent to (partial map f), and (mapper arg ...) is equivalent to (partial map (partial arg ...)).

Examples:
> (require kw-utils/mapper)
> ((mapper add1) '(1 2 3))

'(2 3 4)

> ((mapper +) '(1 2 3) '(4 5 6))

'(5 7 9)

> ((mapper + 3) '(1 2 3))

'(4 5 6)

> ((mapper + 3) '(1 2 3) '(4 5 6))

'(8 10 12)