| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Test.Tasty.Discover.Internal.Unsafe
Description
Unsafe utility functions for internal use.
This module contains partial functions that are used internally where we have strong invariants that guarantee they won't fail, but we want to be explicit about their unsafe nature.
Synopsis
- unsafeHead :: [a] -> a
Documentation
unsafeHead :: [a] -> a Source #
Unsafe head function with descriptive error message.
This function is partial and will throw an error on empty lists. It should only be used when there's a strong invariant guaranteeing the list is non-empty.
Why use this instead of a total function?
- Preserves existing type signatures and caller simplicity
- Makes invariant violations fail fast with clear error messages
- Avoids pushing complexity up the call chain for conditions that should never occur
- Used specifically in
getGeneratorswheregroupBynever produces empty groups
When to use:
- Internal functions with strong invariants
- Performance-critical code where the invariant is guaranteed
- When converting to total functions would complicate the entire call chain
When NOT to use:
- Public APIs where callers might pass invalid input
- When the input domain genuinely includes edge cases
- When safety is more important than performance