-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
anagram: Add an example for list of strings
This is a second example that will fully test (using the proposal #395) that the new tests in #393 correctly accept multiple signatures. This is simply the old example before #395 changed it from acting on `[String]` to `Set Text`
- Loading branch information
1 parent
ace7dae
commit 56eb038
Showing
2 changed files
with
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Anagram (anagramsFor) where | ||
import Data.List (sort) | ||
import Data.Char (toLower) | ||
|
||
anagramsFor :: String -> [String] -> [String] | ||
anagramsFor word = filter (isAnagram . normalize) | ||
where | ||
normalize xs = let nxs = map toLower xs in (nxs, sort nxs) | ||
(nw, sw) = normalize word | ||
isAnagram (w, s) = nw /= w && sw == s |
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,17 @@ | ||
name: anagram | ||
|
||
dependencies: | ||
- base | ||
|
||
library: | ||
exposed-modules: Anagram | ||
source-dirs: src | ||
dependencies: | ||
|
||
tests: | ||
test: | ||
main: Tests.hs | ||
source-dirs: test | ||
dependencies: | ||
- anagram | ||
- hspec |