Behavior when the collection is empty varies -- most often this yields an underflow error , identically to a pop on an empty collection .
Some implementations provide a function which instead simply returns ( without error ) , essentially implementing if isempty then return , else peek .
Behavior when the collection is empty varies -- most often this yields an underflow error , identically to a pop on an empty collection , but some implementations provide a function which instead simply returns ( without error ) , essentially implementing if isempty then return , else peek .