function createSegments(context, startIndex, endIndex, create) {
	/** @type {Array<Array<CodePathSegment>>} */
	const list = context.segmentsList;

	/*
	 * Both `startIndex` and `endIndex` work the same way: if the number is zero
	 * or more, then the number is used as-is. If the number is negative,
	 * then that number is added to the length of the segments list to
	 * determine the index to use. That means -1 for either argument
	 * is the last element, -2 is the second to last, and so on.
	 *
	 * So if `startIndex` is 0, `endIndex` is -1, and `list.length` is 3, the
	 * effective `startIndex` is 0 and the effective `endIndex` is 2, so this function
	 * will include items at indices 0, 1, and 2.
	 *
	 * Therefore, if `startIndex` is -1 and `endIndex` is -1, that means we'll only
	 * be using the last segment in `list`.
	 */
	const normalizedBegin =
		startIndex >= 0 ? startIndex : list.length + startIndex;
	const normalizedEnd = endIndex >= 0 ? endIndex : list.length + endIndex;

	/** @type {Array<CodePathSegment>} */
	const segments = [];

	for (let i = 0; i < context.count; ++i) {
		// this is passed into `new CodePathSegment` to add to code path.
		const allPrevSegments = [];

		for (let j = normalizedBegin; j <= normalizedEnd; ++j) {
			allPrevSegments.push(list[j][i]);
		}

		// note: `create` is just a wrapper that augments `new CodePathSegment`.
		segments.push(create(context.idGenerator.next(), allPrevSegments));
	}

	return segments;
}
Creates a new segment for each fork in the given context and appends it
to the end of the specified range of segments. Ultimately, this ends up calling
`new CodePathSegment()` for each of the forks using the `create` argument
as a wrapper around special behavior.

The `startIndex` and `endIndex` arguments specify a range of segments in
`context` that should become `allPrevSegments` for the newly created
`CodePathSegment` objects.

When `context.segmentsList` is `[[a, b], [c, d], [e, f]]`, `begin` is `0`, and
`end` is `-1`, this creates two new segments, `[g, h]`. This `g` is appended to
the end of the path from `a`, `c`, and `e`. This `h` is appended to the end of
`b`, `d`, and `f`.
@param {ForkContext} context An instance from which the previous segments
     will be obtained.
@param {number} startIndex The index of the first segment in the context
     that should be specified as previous segments for the newly created segments.
@param {number} endIndex The index of the last segment in the context
     that should be specified as previous segments for the newly created segments.
@param {Function} create A function that creates new `CodePathSegment`
     instances in a particular way. See the `CodePathSegment.new*` methods.
@returns {Array<CodePathSegment>} An array of the newly-created segments.