tasty-discover-5.2.0: Test discovery for the tasty framework.
Safe HaskellSafe-Inferred
LanguageHaskell2010

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

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 getGenerators where groupBy never 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