What is the opposite of string.next?

prev or something similar is not in the standard API because succ and a hypoethetical prev are surjective. Despite this, “Implement Ruby String Class Prev / Pred / Prev! / Pred! – Opposite Of Next / Succ Methods” is a possible version you could use.

The root problem is that succ is not inversible. This means, once you applied succ, then prev would end up with some ambiguity.

surjective map of succ and prev

Leave a Comment