# cannot range over func() (value of type func())

- **ID:** `go/cannot-range-over-function`
- **Domain:** go
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

Trying to use range on a function type instead of a slice, map, string, channel, or array.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Go 1.18 | active | — | — |
| Go 1.19 | active | — | — |
| Go 1.20 | active | — | — |
| Go 1.21 | active | — | — |
| Go 1.22 | active | — | — |

## Workarounds

1. **Ensure the function returns a slice or another iterable type, then range over the return value** (95% success)
   ```
   Ensure the function returns a slice or another iterable type, then range over the return value
   ```
2. **Use a channel if you want to iterate over values produced by a function (goroutine + channel pattern)** (85% success)
   ```
   Use a channel if you want to iterate over values produced by a function (goroutine + channel pattern)
   ```

## Dead Ends

- **** — If the function returns a single value that is not iterable, the same error occurs on the return type. (70% fail)
- **** — Go does not allow range on interface{} either; it must be a concrete iterable type. (95% fail)
