@@ -2,13 +2,14 @@ module Data.DataFrame where
2
2
3
3
import Prelude
4
4
5
+ import Control.Apply (lift2 )
5
6
import Data.Compactable (class Compactable , separate )
6
7
import Data.Filterable (class Filterable , partitionMap )
7
8
import Data.Foldable (intercalate , maximum , surround )
8
9
import Data.Function (on )
9
10
import Data.Generic.Rep (class Generic )
10
11
import Data.List (catMaybes , head , mapMaybe , partition , sortBy , take , transpose )
11
- import Data.List (filter ) as List
12
+ import Data.List (filter , length ) as List
12
13
import Data.List.Types (List )
13
14
import Data.Map (Map )
14
15
import Data.Map (toUnfoldable ) as Map
@@ -18,7 +19,6 @@ import Data.Newtype (class Newtype, over, unwrap, wrap)
18
19
import Data.String (length )
19
20
import Data.String.NonEmpty (NonEmptyString )
20
21
import Data.Tuple (fst , snd )
21
- import Data.Tuple.Nested (type (/\))
22
22
23
23
newtype DataFrame a = DataFrame (List a )
24
24
@@ -47,21 +47,28 @@ instance filterableDF :: Filterable DataFrame where
47
47
instance showUntypedDataFrame :: Show a => Show (DataFrame (Map NonEmptyString a )) where
48
48
show =
49
49
unwrap >>>
50
- take 10 >>>
51
- map (Map .toUnfoldable >>> sortBy (compare `on` fst)) >>>
52
- transpose >>>
53
- map drawColumn >>>
54
- transpose >>>
55
- map (surround " | " ) >>> ((flip intercalate) <*> (head >>> maybe 0 length >>> power " -" >>> (_ <> " \n " )))
50
+ (lift2 (<>) (take 10 >>> showSummary) showRemainingCount)
56
51
where
57
- drawColumn :: List (NonEmptyString /\ a ) -> List String
52
+ showSummary =
53
+ map (Map .toUnfoldable >>> sortBy (compare `on` fst))
54
+ >>> transpose
55
+ >>> map drawColumn
56
+ >>> transpose
57
+ >>> map (surround " | " )
58
+ >>> (flip intercalate <*> head >>> maybe 0 length >>> power " -" >>> (_ <> " \n " ))
58
59
drawColumn xs =
59
60
map
60
61
(snd >>> padTo (max (maxLengthOfValues xs) (maybe 0 (fst >>> show >>> length) (head xs))))
61
62
xs
62
- maxLengthOfValues :: List (NonEmptyString /\ a ) -> Int
63
- maxLengthOfValues = map (snd >>> show >>> length) >>> maximum >>> fromMaybe 0
63
+ maxLengthOfValues =
64
+ map (snd >>> show >>> length)
65
+ >>> maximum
66
+ >>> fromMaybe 0
64
67
padTo :: Int -> a -> String
65
68
padTo i a =
66
69
let pad = power " " $ (i - length (show a)) / 2
67
70
in pad <> show a <> pad
71
+ showRemainingCount =
72
+ List .length >>>
73
+ (_ - 10 ) >>>
74
+ ((\l -> if _ then " \n ... and " <> show l <> " more" else mempty) <*> (_ > 0 ))
0 commit comments