Skip to content

Commit

Permalink
anagram: Add an example for list of strings
Browse files Browse the repository at this point in the history
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
petertseng committed Oct 12, 2016
1 parent ace7dae commit 56eb038
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
10 changes: 10 additions & 0 deletions exercises/anagram/examples/list-string/Anagram.hs
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
17 changes: 17 additions & 0 deletions exercises/anagram/examples/list-string/package.yaml
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

0 comments on commit 56eb038

Please sign in to comment.