Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

diamond: Change return type to Maybe #653

Merged
merged 1 commit into from
Feb 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions exercises/diamond/examples/success-standard/src/Diamond.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ oneRow :: Char -> (Int, Int) -> String
oneRow c (0, y) = pad y ++ [c] ++ pad y
oneRow c (x, y) = pad y ++ [c] ++ pad x ++ [c] ++ pad y

diamond :: Char -> [String]
diamond = (\x -> x ++ tail (reverse x)) . mkTop . subtract 64 . ord
diamond :: Char -> Maybe [String]
diamond = Just . (\x -> x ++ tail (reverse x)) . mkTop . subtract 64 . ord
where rows x = zip (0 : take (x-1) [1, 3..]) [x-1, x-2..0]
mkTop = zipWith oneRow abc . rows
abc = map chr [65..90]
2 changes: 1 addition & 1 deletion exercises/diamond/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: diamond
version: 1.1.0.2
version: 1.1.0.3

dependencies:
- base
Expand Down
2 changes: 1 addition & 1 deletion exercises/diamond/src/Diamond.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Diamond (diamond) where

diamond :: Char -> [String]
diamond :: Char -> Maybe [String]
diamond = error "You need to implement this function"
2 changes: 1 addition & 1 deletion exercises/diamond/test/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ specs = describe "diamond" $ for_ cases test

test Case{..} = it description assertion
where
assertion = diamond input `shouldBe` expected
assertion = diamond input `shouldBe` Just expected


data Case = Case { description :: String
Expand Down