@@ -2,11 +2,11 @@ module FileOperations where
2
2
3
3
import Prelude
4
4
import Control.MonadZero (guard )
5
- import Data.Array (uncons , length , filter , concatMap , (:), (..))
6
- import Data.Array.Partial (tail , head )
5
+ import Data.Array (snoc , uncons , length , filter , concatMap , (:), (..))
6
+ import Data.Array.Partial (last , init , tail , head )
7
7
import Data.Foldable (foldl )
8
8
import Data.Maybe (Maybe (Just, Nothing))
9
- import Data.Path (Path , ls )
9
+ import Data.Path (size , isDirectory , Path , ls )
10
10
import Partial.Unsafe (unsafePartial )
11
11
12
12
allFiles :: Path -> Array Path
@@ -94,3 +94,17 @@ count p = count' 0
94
94
95
95
reverse :: forall a . Array a -> Array a
96
96
reverse = foldl (\acc n -> n : acc) []
97
+
98
+ onlyFiles :: Path -> Array Path
99
+ onlyFiles = filter (not isDirectory) <<< allFiles
100
+
101
+ largestAndSmallest :: Path -> Array Path
102
+ largestAndSmallest = foldl check [] <<< onlyFiles
103
+ where
104
+ check [] path = [path, path]
105
+ check acc path =
106
+ if size path > size (unsafePartial head acc)
107
+ then path : (unsafePartial tail acc)
108
+ else if size path < size (unsafePartial last acc)
109
+ then (unsafePartial init acc) `snoc` path
110
+ else acc
0 commit comments