toOffsetLimit

open fun toOffsetLimit(defaultPageSize: Int): OffsetLimit(source)

Converts backward pagination arguments to offset/limit.

  • getLast determines the page size (defaults to defaultPageSize).
  • getBefore cursor encodes the index of the first item on the next page; the offset and limit are computed to return the last items ending just before that position, clamped so the window never extends before index 0.
  • If before is absent, a negative offset equal to -pageSize is returned, signalling fromList to resolve from the tail of the full list. Prefer toOffsetLimit with the total count when available.

open fun toOffsetLimit(totalCount: Int, defaultPageSize: Int): OffsetLimit(source)

Converts backward pagination arguments to offset/limit when the total count is known.

When getBefore is absent, this computes the offset as max(0, totalCount - last) to return the last N items from the dataset, avoiding the negative-offset signal used by toOffsetLimit. When before is present, totalCount is ignored and this delegates to toOffsetLimit.

Parameters

totalCount

total number of items in the full dataset

defaultPageSize

default number of items when last not specified