-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChangingDirections.hs
More file actions
21 lines (19 loc) · 899 Bytes
/
ChangingDirections.hs
File metadata and controls
21 lines (19 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module ChangingDirections where
import FileSystem (FileSystem(..))
import MyStack (headMaybe)
import Predicates (isNameOfFolder)
import ExtendedOperations ( nameOfRoot )
changeDir :: String -> [FileSystem] -> Maybe FileSystem
changeDir name xs = headMaybe $ filter (isNameOfFolder name) xs
changeEntity :: FileSystem -> FileSystem -> FileSystem
changeEntity new old@(Root n xs) =
case nameOfRoot new of
Nothing -> old
Just name' -> if name' == n then new else Root n $ changeEntityDeep new xs
where
changeEntityDeep :: FileSystem -> [FileSystem] -> [FileSystem]
changeEntityDeep new@(Root n xs) (old@(Root n' xss) : xs')
| n == n' = new : xs'
| otherwise = Root n' (changeEntityDeep new xss) : changeEntityDeep new xs'
changeEntityDeep new (old : xs') = old : changeEntityDeep new xs'
changeEntityDeep _ x = x