sublists (empty) → 0.1.0.0
raw patch · 5 files changed
+96/−0 lines, 5 filesdep +basesetup-changed
Dependencies added: base
Files
- ChangeLog.md +5/−0
- LICENSE +20/−0
- Setup.hs +2/−0
- Sublists.hs +44/−0
- sublists.cabal +25/−0
+ ChangeLog.md view
@@ -0,0 +1,5 @@+# Revision history for sublists++## 0.1.0.0 -- 2021-03-03++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2021 OleksandrZhabenko++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ Sublists.hs view
@@ -0,0 +1,44 @@+-- |+-- 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++{-| 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*.++If the first argument is less than 1 then returns an infinite lazy list of the [] as its elements (probably not the needed case).++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 #-}
+ sublists.cabal view
@@ -0,0 +1,25 @@+-- Initial sublists.cabal generated by cabal init. For further+-- documentation, see http://haskell.org/cabal/users-guide/++name: sublists+version: 0.1.0.0+synopsis: Allows to split lists into sublists with some patterns by quantity.+description: This patterns can be a number, a list of numbers or obtained from the monadic function. Leads to somewhat cycling or regularized structures from the length perspective (this 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+copyright: Oleksandr Zhabenko+category: Data+build-type: Simple+extra-source-files: ChangeLog.md+cabal-version: >=1.10++library+ exposed-modules: Sublists+ -- other-modules:+ -- other-extensions:+ build-depends: base >=4.7 && <4.15+ -- hs-source-dirs:+ default-language: Haskell2010