packages feed

basesystems-1.1.0.0: basesystems/Data/BaseSystem/Internal.hs

-- | Module      : Data.BaseSystem.Internal
--   Description : Provides common resources for multibase
--   Copyright   : Zoey McBride (c) 2026
--   License     : BSD-3-Clause
--   Maintainer  : zoeymcbride@mailbox.org
--   Stability   : experimental
--
-- Common data definitions and helper functions for this library.
module Data.BaseSystem.Internal
  ( -- * List utilities
    replaceNull,
    iterateInit,
  )
where

-- | Return the the first param if the second param is empty.
{-# INLINE replaceNull #-}
replaceNull :: [a] -> [a] -> [a]
replaceNull replace xs
  | null xs = replace
  | otherwise = xs

-- | Wraps iterate to compose with an intermediary type constructor.
iterateInit :: (b -> b) -> (a -> b) -> a -> [b]
iterateInit f iterinit = drop 1 . iterate f . iterinit