Neat! I did it the same way. So concise.
pageItemCount is really clever and in functional style + when not Nothing uses less memory then most of solutions here.
This comment is hidden because it contains spoiler information about the solution
This doesn’t satisfy “An invalid program should raise a type error rather than a runtime error.”