:: [a] -> a package:tasty-discover

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