---
title: "prefix(_:)"
framework: combine
role: symbol
role_heading: Instance Method
path: "combine/publisher/prefix(_:)"
---

# prefix(_:)

Republishes elements up to the specified maximum count.

## Declaration

```swift
func prefix(_ maxLength: Int) -> Publishers.Output<Self>
```

## Parameters

- `maxLength`: The maximum number of elements to republish.

## Return Value

Return Value A publisher that publishes up to the specified number of elements.

## Discussion

Discussion Use prefix(_:) to limit the number of elements republished to the downstream subscriber. In the example below, the prefix(_:) operator limits its output to the first two elements before finishing normally: let numbers = (0...10) cancellable = numbers.publisher     .prefix(2)     .sink { print("\($0)", terminator: " ") }

// Prints: "0 1"

## See Also

### Applying sequence operations to elements

- [drop(untilOutputFrom:)](combine/publisher/drop(untiloutputfrom:).md)
- [dropFirst(_:)](combine/publisher/dropfirst(_:).md)
- [drop(while:)](combine/publisher/drop(while:).md)
- [tryDrop(while:)](combine/publisher/trydrop(while:).md)
- [append(_:)](combine/publisher/append(_:)-1qb8d.md)
- [append(_:)](combine/publisher/append(_:)-69sdn.md)
- [append(_:)](combine/publisher/append(_:)-5yh02.md)
- [prepend(_:)](combine/publisher/prepend(_:)-7wk5l.md)
- [prepend(_:)](combine/publisher/prepend(_:)-v9sb.md)
- [prepend(_:)](combine/publisher/prepend(_:)-5dj9c.md)
- [prefix(while:)](combine/publisher/prefix(while:).md)
- [tryPrefix(while:)](combine/publisher/tryprefix(while:).md)
- [prefix(untilOutputFrom:)](combine/publisher/prefix(untiloutputfrom:).md)
