static <T, S extends Seq<T>> Collector<T, Buffer<T>, S>
	toSeq(final int maxSize, final Function<Buffer<T>, S> finisher) {
		if (maxSize < 0) {
			throw new IllegalArgumentException(format(
				"Max size is negative: %d", maxSize
			));
		}
		return maxSize > 0
			? Collector.of(
				() -> Buffer.ofCapacity(maxSize),
				Buffer::add,
				(l, r) -> {l.addAll(r); return l;},
				finisher)
			: Collector.of(
				() -> null,
				(buffer, value) -> {},
				(left, right) -> left,
				buffer -> {
					@SuppressWarnings("unchecked") final S seq = (S) Seq.empty();
					return seq;
				});
	}
Returns a {@code Collector} that accumulates the last {@code n} input
elements into a new {@code ISeq}.

@since 5.0

@param maxSize the maximal size of the collected sequence
@param <T> the type of the input elements
@param <S> the sequence type
@return a {@code Collector} which collects maximal {@code maxSize} of the
        input elements into an {@code ISeq}, in encounter order
@throws IllegalArgumentException if the {@code maxSize} is negative
jenetics/src/main/java/io/jenetics/util/Seqs.java