# Contract for (λ (x . rest) x)

**URL:** <https://racket.discourse.group/t/contract-for-x-rest-x/325>\
**Category:** Questions & Answers\
**Tags:** question\
**Created:** [December 1, 2021, 4:08pm UTC](https://racket.discourse.group/t/contract-for-x-rest-x/325 "2021-12-01T16:08:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![badkins](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/badkins/32/99_2.png) [@badkins](https://racket.discourse.group/u/badkins)\
**Post date:** [December 1, 2021, 4:08pm UTC](https://racket.discourse.group/t/contract-for-x-rest-x/325/1 "2021-12-01T16:08:13Z")

</div>

The [documentation for `->*`](https://docs.racket-lang.org/reference/function-contracts.html#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._-~3e%2A%29%29) mentions a particular contract not matching `(λ (x . rest) x)` due to the rest args not being optional, but I was unable to find a contract that _does_ match that function.

What contract matches that function?

---

<div class="post-metadata">

**Author:** ![badkins](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/badkins/32/99_2.png) [@badkins](https://racket.discourse.group/u/badkins)\
**Post date:** [December 1, 2021, 4:12pm UTC](https://racket.discourse.group/t/contract-for-x-rest-x/325/2 "2021-12-01T16:12:53Z")

</div>

Rubber duck works again 🙂

```scheme
[zipn (-> list? ... list?)]

```

Of course, my scenario is simplified since all the rest args are of the same type.

---

<div class="post-metadata">

**Author:** ![kablooey](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/kablooey/32/226_2.png) [@kablooey](https://racket.discourse.group/u/kablooey)\
**Post date:** [December 6, 2021, 7:21pm UTC](https://racket.discourse.group/t/contract-for-x-rest-x/325/3 "2021-12-06T19:21:01Z")

</div>

The contract `(->* (integer?) #:rest (listof integer?) any)` should do the trick.

The REPL seems to agree.

```scheme
% rlwrap racket
Welcome to Racket v8.2 [cs].
> (define/contract (f x . rest)
    (->* (integer?) #:rest (listof integer?) any)
    x)
> (f 2)
2
> (f 2 3 4)
2
> (f "racket" 2 3 4)
f: contract violation
  expected: integer?
  given: "racket"
  in: the 1st argument of
      (->*
       (integer?)
       #:rest
       (listof integer?)
       any)
  contract from: (function f)
  blaming: top-level
   (assuming the contract is correct)
  at: stdin::50-51
  context...:
   /usr/local/Cellar/minimal-racket/8.2/share/racket/collects/racket/contract/private/blame.rkt:346:0: raise-blame-error
   /usr/local/Cellar/minimal-racket/8.2/share/racket/collects/racket/contract/private/arrow-higher-order.rkt:375:33
   /usr/local/Cellar/minimal-racket/8.2/share/racket/collects/racket/repl.rkt:11:26
> (f 2 "racket" "rhombus" "scribble")
f: contract violation
  expected: integer?
  given: "racket"
  in: an element of
      the rest argument of
      (->*
       (integer?)
       #:rest
       (listof integer?)
       any)
  contract from: (function f)
  blaming: top-level
   (assuming the contract is correct)
  at: stdin::50-51
  context...:
   /usr/local/Cellar/minimal-racket/8.2/share/racket/collects/racket/contract/private/blame.rkt:346:0: raise-blame-error
   /usr/local/Cellar/minimal-racket/8.2/share/racket/collects/racket/contract/private/list.rkt:215:14
   /usr/local/Cellar/minimal-racket/8.2/share/racket/collects/racket/contract/private/arrow-higher-order.rkt:375:33
   /usr/local/Cellar/minimal-racket/8.2/share/racket/collects/racket/repl.rkt:11:26

```
