Some encoders have only one optical, magnetic or mechanic sensor. So these encoders cannot detect direction of the rotation. But in case our soft controls the motor and therefore we know the current direction, these encoders are useful to calculate distance and velocity.
Here is a small Arduino library just for these encoders. I've made it for my hobby robotic project, but I believe this library can be handy in other projects. Feel free to fork and modify it.
To install the library go to releases, download single_pin_encoder.zip from the latest release and follow Importing a .zip Library instructions.