Skip to content

Commit 082072b

Browse files
authored
Ch4 change 'whereIs' function signature (#218)
Change 'whereIs' signature so it accepts an arbitary path as an argument. Update the instruction to show that it should take an additional path parameter. Correcting file names in the instuction so they do not contain their base paths.
1 parent 8e55a3c commit 082072b

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

exercises/chapter4/test/Main.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ Note to reader: Delete this line to expand comment block -}
162162
suite "Exercise - whereIs" do
163163
test "locates a file"
164164
$ Assert.equal (Just ("/bin/"))
165-
$ whereIs "ls"
165+
$ whereIs root "ls"
166166
test "doesn't locate a file"
167167
$ Assert.equal (Nothing)
168-
$ whereIs "lss"
168+
$ whereIs root "cat"
169169

170170
{- Note to reader: Delete this line to expand comment block
171171
-}

exercises/chapter4/test/no-peeking/Solutions.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Data.Array (cons, filter, head, last, length, tail, (..))
66
import Data.Foldable (foldl)
77
import Data.Int (rem, quot)
88
import Data.Maybe (Maybe(..), fromMaybe, maybe)
9-
import Data.Path (Path, filename, isDirectory, ls, root, size)
9+
import Data.Path (Path, filename, isDirectory, ls, size)
1010
import Data.String.Common (split)
1111
import Data.String.Pattern (Pattern(..))
1212
import Data.Tuple (Tuple(..), snd)
@@ -127,8 +127,8 @@ allSizes paths =
127127
)
128128
paths
129129

130-
whereIs :: String -> Maybe String
131-
whereIs fileName = head $ whereIs' $ allFiles root
130+
whereIs :: Path -> String -> Maybe String
131+
whereIs path fileName = head $ whereIs' $ allFiles path
132132
where
133133
whereIs' :: Array Path -> Array String
134134
whereIs' paths = do

text/chapter4.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,10 +647,10 @@ Try out the new version in PSCi - you should get the same result. I'll let you d
647647
1. (Difficult) Write a function `whereIs` to search for a file by name. The function should return a value of type `Maybe Path`, indicating the directory containing the file, if it exists. It should behave as follows:
648648

649649
```text
650-
> whereIs "/bin/ls"
650+
> whereIs root "ls"
651651
Just (/bin/)
652652
653-
> whereIs "/bin/cat"
653+
> whereIs root "cat"
654654
Nothing
655655
```
656656

0 commit comments

Comments
 (0)