-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Valeriy Popov
committed
Dec 10, 2017
1 parent
fc886b5
commit 0e3bf33
Showing
5 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Chapter2.SimpleFunctions ( | ||
firstOrEmpty, | ||
(+++), | ||
reverse2 | ||
) where | ||
|
||
firstOrEmpty :: [String] -> String | ||
firstOrEmpty lst = if not (null lst) then head lst else "empty" | ||
|
||
|
||
lst1 +++ lst2 = if null lst1 | ||
then lst2 | ||
else (head lst1) : (tail lst1 +++ lst2) | ||
|
||
|
||
reverse2 list = if null list | ||
then [] | ||
else reverse2 (tail list) +++ [head list] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Chapter2.SimpleFunctionsSpec where | ||
|
||
import Test.Hspec | ||
import Chapter2.SimpleFunctions | ||
|
||
spec :: Spec | ||
spec = do | ||
describe "Prelude.head" $ do | ||
|
||
it "reverse the string" $ do | ||
reverse2 "hello" `shouldBe` "olleh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{-# OPTIONS_GHC -F -pgmF hspec-discover #-} |