IList: safe, invariant cons list

Cherry-picking #611

Contribution by @tpolecat and @S11001001
some optimization and refactoring for IList

Cherry-picking fb52afa
more random tests for IList

Cherry-picking 3d376a9
optimize IList#takeRight, takeRightWhile, collect

Cherry-picking 0285b5f
optimize IList#scanLeft, scanRight

Cherry-picking 4f45e9a