packages feed

sublists 0.1.2.0 → 0.2.0.0

raw patch · 5 files changed

+72/−63 lines, 5 filesdep ~base

Dependency ranges changed: base

Files

ChangeLog.md view
@@ -16,8 +16,13 @@  * First version revised C. Added variant of the Applicative usage. -## 0.1.r21.0 -- 2022-08-17+## 0.1.2.0 -- 2022-08-17  * First version revised D. Updated dependency boundaries to support the newer GHC-9* versions. +## 0.2.0.0 -- 2023-05-04++* Second version. Changed the module name to the more expected one. Added README.md file +with devotion to Foundation Gastrostars. Switched to NoImplicitPrelude extension +and updated the dependency boundaries. 
+ Data/List/CyclingSublists.hs view
@@ -0,0 +1,60 @@+-- |+-- Module      :  Data.List.CyclingSublists+-- Copyright   :  (c) OleksandrZhabenko 2021-2023+-- License     :  MIT+-- Stability   :  Experimental+-- Maintainer  :  oleksandr.zhabenko@yahoo.com+--+-- Allows to split lists into sublists with some patterns by quantity.++{-# LANGUAGE NoImplicitPrelude #-}++module Data.List.CyclingSublists where++import GHC.Base+import GHC.List (splitAt, null)+import Control.Applicative (Applicative,pure,(<*>))+import Data.Functor ((<$>))++{-| Splits the input second argument into sublists each one containing the @n@ elements where the number is taken as the+sequential element in the first argument starting from the left to the right. If the number is less than 1 then the+corresponding sublist is empty. If all the elements in the first argument are less than 1 then returns an infinite lazy list of+[] as its elements (probably not the needed case). When all the elements of the first argument ends and there are elements in+the second argument being not already processed then the function reinitializes itself with the prior first argument and the+rest of the unprocessed elements in the second argument. This leads to the *cycling behaviour*.++Similar functions are in the @list-grouping@ and @split@ packages, but they do not have cycling behaviour and have another realization. -}+intoRegularSublists :: [Int] -> [a] -> [[a]]+intoRegularSublists (n:ns) xs + | null xs = []+ | otherwise = ts : intoRegularSublists' ns zs (n:ns)+     where (ts, zs) = splitAt n xs+           intoRegularSublists' (r:rs) ys us+             | null ys = []+             | otherwise = ws : intoRegularSublists' rs vs us+                 where (ws,vs) = splitAt r ys+           intoRegularSublists' _ ys us = intoRegularSublists' us ys us+intoRegularSublists _ xs = [xs]+{-# INLINABLE intoRegularSublists #-}++{-| A monadic variant of the 'intoRegularSublists' where the first argument is taken from the monadic function. -}+intoRegularSublistsM :: (Monad m)+  => (a -> m [Int]) -- ^ A monadic function to obtain the argument for the regularization.+  -> a -- ^ An initial element (seed) for the monadic function.+  -> [b] -- ^ A list to be splitted into the sublists.+  -> m [[b]]+intoRegularSublistsM f seed xs+ | null xs = return []+ | otherwise = f seed >>= \ns -> return . intoRegularSublists ns $ xs+{-# INLINABLE intoRegularSublistsM #-}++{-| An 'Applicative' variant of the 'intoRegularSublists' where the first argument is taken from the applicative function. -}+intoRegularSublistsA :: (Applicative f)+  => (a -> f [Int]) -- ^ An 'Applicative' function to obtain the argument for the regularization.+  -> a -- ^ An initial element (seed) for the applicative function.+  -> [b] -- ^ A list to be splitted into the sublists.+  -> f [[b]]+intoRegularSublistsA f seed xs+ | null xs = pure []+ | otherwise = (\ns xs -> intoRegularSublists ns xs) <$> f seed <*> pure xs+{-# INLINABLE intoRegularSublistsA #-}
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2021-2022 Oleksandr Zhabenko+Copyright (c) 2021-2023 Oleksandr Zhabenko  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the
− Sublists.hs
@@ -1,56 +0,0 @@--- |--- Module      :  Sublists--- Copyright   :  (c) OleksandrZhabenko 2021--- License     :  MIT--- Stability   :  Experimental--- Maintainer  :  olexandr543@yahoo.com------ Allows to split lists into sublists with some patterns by quantity.--module Sublists where--import Control.Applicative (Applicative,pure,(<*>))-import Data.Functor ((<$>))--{-| Splits the input second argument into sublists each one containing the @n@ elements where the number is taken as the-sequential element in the first argument starting from the left to the right. If the number is less than 1 then the-corresponding sublist is empty. If all the elements in the first argument are less than 1 then returns an infinite lazy list of-[] as its elements (probably not the needed case). When all the elements of the first argument ends and there are elements in-the second argument being not already processed then the function reinitializes itself with the prior first argument and the-rest of the unprocessed elements in the second argument. This leads to the *cycling behaviour*.--Similar functions are in the @list-grouping@ and @split@ packages, but they do not have cycling behaviour and have another realization. -}-intoRegularSublists :: [Int] -> [a] -> [[a]]-intoRegularSublists (n:ns) xs - | null xs = []- | otherwise = ts : intoRegularSublists' ns zs (n:ns)-     where (ts, zs) = splitAt n xs-           intoRegularSublists' (r:rs) ys us-             | null ys = []-             | otherwise = ws : intoRegularSublists' rs vs us-                 where (ws,vs) = splitAt r ys-           intoRegularSublists' _ ys us = intoRegularSublists' us ys us-intoRegularSublists _ xs = [xs]-{-# INLINABLE intoRegularSublists #-}--{-| A monadic variant of the 'intoRegularSublists' where the first argument is taken from the monadic function. -}-intoRegularSublistsM :: (Monad m)-  => (a -> m [Int]) -- ^ A monadic function to obtain the argument for the regularization.-  -> a -- ^ An initial element (seed) for the monadic function.-  -> [b] -- ^ A list to be splitted into the sublists.-  -> m [[b]]-intoRegularSublistsM f seed xs- | null xs = return []- | otherwise = f seed >>= \ns -> return . intoRegularSublists ns $ xs-{-# INLINABLE intoRegularSublistsM #-}--{-| An 'Applicative' variant of the 'intoRegularSublists' where the first argument is taken from the applicative function. -}-intoRegularSublistsA :: (Applicative f)-  => (a -> f [Int]) -- ^ An 'Applicative' function to obtain the argument for the regularization.-  -> a -- ^ An initial element (seed) for the applicative function.-  -> [b] -- ^ A list to be splitted into the sublists.-  -> f [[b]]-intoRegularSublistsA f seed xs- | null xs = pure []- | otherwise = (\ns xs -> intoRegularSublists ns xs) <$> f seed <*> pure xs-{-# INLINABLE intoRegularSublistsA #-}
sublists.cabal view
@@ -2,14 +2,14 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                sublists-version:             0.1.2.0+version:             0.2.0.0 synopsis:            Allows to split lists into sublists with some patterns by quantity. description:         These patterns can be a list of numbers, or obtained from the monadic or applicative function. Leads to somewhat cycling or regularized structures from the length perspective (these ones can be transformed into other variativity types). homepage:            https://hackage.haskell.org/package/sublists license:             MIT license-file:        LICENSE author:              OleksandrZhabenko-maintainer:          olexandr543@yahoo.com+maintainer:          oleksandr.zhabenko@yahoo.com copyright:           Oleksandr Zhabenko category:            Data build-type:          Simple@@ -17,9 +17,9 @@ cabal-version:       >=1.10  library-  exposed-modules:     Sublists+  exposed-modules:     Data.List.CyclingSublists   -- other-modules:-  -- other-extensions:-  build-depends:       base >=4.7 && <5+  other-extensions:    NoImplicitPrelude+  build-depends:       base >=4.13 && <5   -- hs-source-dirs:   default-language:    Haskell2010