# Unclear mechanics of Swift 5.7's 'any' keyword

**URL:** <https://forums.swift.org/t/unclear-mechanics-of-swift-5-7s-any-keyword/60179>\
**Category:** Using Swift\
**Created:** [September 8, 2022, 10:19am UTC](https://forums.swift.org/t/unclear-mechanics-of-swift-5-7s-any-keyword/60179 "2022-09-08T10:19:22Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![anon9791410](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@anon9791410](https://forums.swift.org/u/anon9791410)\
**Post date:** [September 8, 2022, 3:22pm UTC](https://forums.swift.org/t/unclear-mechanics-of-swift-5-7s-any-keyword/60179/2 "2022-09-08T15:22:36Z")

</div>

> [@rockbruno](#):
>
> I have a question about the mechanics of the existential `any` keyword that I couldn't find in the proposal.

It's right before [Moving between `any` and `some`](https://github.com/apple/swift-evolution/blob/main/proposals/0352-implicit-open-existentials.md#moving-between-any-and-some).

> To have the effects of opening persist over multiple statements, factor that code out into a generic function

* * *

Applied here, what you're looking for is `$0` to transform into a more magical version of this:

```swift
func animal(_ animal: some Animal) -> some Animal {
  animal
}

```

AKA this, without a named constant:

```swift
let animal: some Animal = animal

```

But it won't do that. When you input an "`any`" into something like that, you get an `any` back out, despite what the keyword on the return type might seem to suggest.

```swift
let animal = animal($0) // any Animal
let food = provider.getFood(for: animal) // Any

```

You also cannot get around the problem using a closure, i.e.

```swift
func unbox<A: Animal>(_ animal: A, _ ƒ: (A) -> Void) {
  ƒ(animal)
}

```

```swift
unbox($0) {
  let food = provider.getFood(for: $0)
  $0.eat(food)
}

```

But you can define the necessary function locally:

```swift
animals.forEach {
  func feed(_ animal: some Animal) {
    animal.eat(provider.getFood(for: animal))
  }
  feed($0)
}

```

It looks ridiculous in context! No clue if it's solvable.

---

_[View the full topic](https://forums.swift.org/t/unclear-mechanics-of-swift-5-7s-any-keyword/60179)._
