halfsplit (empty) → 0.1.0.0
raw patch · 5 files changed
+139/−0 lines, 5 filesdep +base
Dependencies added: base
Files
- CHANGELOG.md +7/−0
- LICENSE +20/−0
- Phladiprelio/Halfsplit.hs +68/−0
- README.md +10/−0
- halfsplit.cabal +34/−0
+ CHANGELOG.md view
@@ -0,0 +1,7 @@+# Revision history for halfsplit++## 0.1.0.0 -- 2023-06-15++* First version. Released on an unsuspecting world.++
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2023 Oleksandr Zhabenko++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.
+ Phladiprelio/Halfsplit.hs view
@@ -0,0 +1,68 @@++-- |+-- Module : Phladiprelio.Halfsplit+-- Copyright : (c) OleksandrZhabenko 2023+-- License : MIT+-- Stability : Experimental+-- Maintainer : oleksandr.zhabenko@yahoo.com+--++{-# LANGUAGE NoImplicitPrelude #-}++{-# OPTIONS_HADDOCK -show-extensions #-}++module Phladiprelio.Halfsplit where++import GHC.Base+import GHC.Enum (fromEnum)+import GHC.Real (quot,quotRem)+import GHC.Num ((+),(-),abs)+import Data.List hiding (foldr)+import GHC.Int (Int8)+import Text.Show (Show(..))++-- | Converts the data that is an instance of 'Show' typeclass to be printed in two-column way.+halfsplit + :: (Show a, Eq b) + => (a -> b)+ -> Int8 + -> [a] + -> String+halfsplit g m xs + | null xs = []+ | otherwise = + let (n, rr2) = quotRem (fromEnum m) (if m < 0 then -10 else 10)+ r = + case abs rr2 of+ 1 -> let us = reverse ts in (if rrr == 0 then map show ys else replicate l0 ' ':map show ys, map show us)+ 2 -> let us = (replicate (lt1 - ly1) [replicate l0 ' ']) `mappend` reverse (map reverse y1s) in (mconcat us, mconcat t1s)+ 3 -> let us = (replicate (lt1 - ly1) [replicate l0 ' ']) `mappend` y1s+ ks = reverse . map reverse $ t1s in (mconcat us, mconcat ks)+ 4 -> let us = (replicate (lt2 - ly2) [replicate l0 ' ']) `mappend` reverse (map reverse y2s) in (mconcat us, mconcat t2s)+ 5 -> let us = (replicate (lt2 - ly2) [replicate l0 ' ']) `mappend` y2s+ ks = reverse . map reverse $ t2s in (mconcat us, mconcat ks)+ _ -> let us = reverse ys in (if rrr == 0 then map show us else replicate l0 ' ':map show us, map show ts) in (\(rs, qs) -> mergePartsLine n "\n" rs qs) $ r+ where (ys,ts) = splitAt l xs + (l,rrr) = length xs `quotRem` 2+ l0 = length . show . head $ xs + rss = map (map show) . groupBy (\x y -> g x == g y) $ xs+ r1ss = intersperse [replicate l0 ' '] rss+ l2 = (sum . map length $ rss) `quot` 2+ l3 = (sum . map length $ r1ss) `quot` 2+ (y1s,t1s,_) = splitGroups l2 rss+ ly1 = sum . map length $ y1s+ lt1 = sum . map length $ t1s+ (y2s,t2s,_) = splitGroups l3 r1ss+ ly2 = sum . map length $ y2s+ lt2 = sum . map length $ t2s+++mergePartsLine :: Int -> String -> [String] -> [String] -> String+mergePartsLine n newlined xs ys = intercalate newlined . zipWith (\x y -> x `mappend` (replicate n (if n < 0 then '\t' else ' ')) `mappend` y) xs $ ys++splitGroups :: Int -> [[a]] -> ([[a]], [[a]], Int)+splitGroups l tss = foldr h ([],[],0) tss+ where h js (rss,mss,k)+ | k < l = (rss, js:mss, k + length js)+ | otherwise = (js : rss, mss, k + length js)+
+ README.md view
@@ -0,0 +1,10 @@+ Devotion+ ========++The author would like to devote this project to support the Foundation GASTROSTARS.++If you would like to share some financial support, please, contact the foundation+using the URL:++[Contact Foundation GASTROSTARS](https://gastrostars.nl/hou-mij-op-de-hoogte)+
+ halfsplit.cabal view
@@ -0,0 +1,34 @@+cabal-version: 2.4+name: halfsplit+version: 0.1.0.0++-- A short (one-line) description of the package.+synopsis: A library to provide special kind of two-column terminal output for Phladiprelio. ++-- A longer description of the package.+description: Provides function for two-column terminal output for newer versions of Phladiprelio projects. Is intended to improve UI and UX for the work with them. ++-- A URL where users can report bugs.+-- bug-reports:++-- The license under which the package is released.+license: MIT+license-file: LICENSE+author: Oleksandr Zhabenko+maintainer: oleksandr.zhabenko@yahoo.com++-- A copyright notice.+copyright: Oleksandr Zhabenko+category: Language, Data+extra-source-files: CHANGELOG.md, README.md++library+ -- Modules included in this executable, other than Main.+ exposed-modules: Phladiprelio.Halfsplit++ -- LANGUAGE extensions used by modules in this package.+ other-extensions: NoImplicitPrelude+ build-depends: base >=4.13 && <5+ hs-source-dirs: .+ default-language: Haskell2010+