{-|
Module      : Nauty.Internal.Utils
Description : Internal functions.
Copyright   : (c) Marcelo Garlet Milani, 2025
License     : GPL-3
Maintainer  : mgmilani@pm.me
Stability   : unstable

This module contains internal functions used by other modules.
Except for test cases, you should not import this module.
-}

{-# LANGUAGE OverloadedStrings #-}

module Nauty.Internal.Utils where

-- |Group a list of elements two-by-two.
groupByTwo :: [a] -> [(a,a)]
groupByTwo :: forall a. [a] -> [(a, a)]
groupByTwo (a
x:a
y:[a]
xs) = (a
x,a
y) (a, a) -> [(a, a)] -> [(a, a)]
forall a. a -> [a] -> [a]
: [a] -> [(a, a)]
forall a. [a] -> [(a, a)]
groupByTwo [a]
xs
groupByTwo [a]
_ = []

-- |Ungroup components of each pair.
ungroupByTwo :: [(a,a)] -> [a]
ungroupByTwo :: forall a. [(a, a)] -> [a]
ungroupByTwo ((a
a,a
b) : [(a, a)]
xs) = a
a a -> [a] -> [a]
forall a. a -> [a] -> [a]
: a
b a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [(a, a)] -> [a]
forall a. [(a, a)] -> [a]
ungroupByTwo [(a, a)]
xs
ungroupByTwo [(a, a)]
_ = []