-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Approved-by: ReinierMaas Auto-deploy: false
- Loading branch information
Showing
13 changed files
with
83 additions
and
14 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,3 @@ | ||
self: super: { | ||
hashable = super.hashable_1_4_0_2; | ||
} |
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,6 @@ | ||
self: super: | ||
let | ||
haskellOverlay = import ./haskell-overlay.nix; | ||
in { | ||
Ghc902Packages = super.haskell.packages.ghc902.extend haskellOverlay; | ||
} |
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
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 |
---|---|---|
|
@@ -55,3 +55,4 @@ tests: | |
- hspec-expectations | ||
- directory | ||
- QuickCheck | ||
- quickcheck-instances |
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,25 @@ | ||
-- | KeyMap, extending Aeson.KeyMap to support replacing HashMap. | ||
module KeyMap | ||
( KeyMap | ||
, lookupDefault | ||
, lookup | ||
, mapMaybe | ||
, fromList | ||
, toList | ||
|
||
, Key | ||
, fromText | ||
, toText | ||
, fromString | ||
, toString | ||
) where | ||
|
||
import Data.Aeson.Key (Key, fromText, toText, fromString, toString) | ||
import Data.Aeson.KeyMap (KeyMap, mapMaybe, fromList, toList) | ||
import Data.Maybe (fromMaybe) | ||
|
||
import qualified Data.Aeson.KeyMap as KM | ||
|
||
-- | lookupDefault for KeyMap based on lookupDefault from HashMap. | ||
lookupDefault :: v -> Key -> KeyMap v -> v | ||
lookupDefault d k km = fromMaybe d $ KM.lookup k km |
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,25 @@ | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
|
||
module KeyMapSpec where | ||
|
||
import Data.Text (Text) | ||
import Test.Hspec | ||
import Test.QuickCheck | ||
import Test.QuickCheck.Instances () | ||
|
||
import qualified Data.HashMap.Internal.Strict as HM | ||
|
||
import qualified KeyMap as KM | ||
|
||
mapFirst :: (a->b) -> [(a,c)] -> [(b,c)] | ||
mapFirst _ [] = [] | ||
mapFirst f ((x,y) : rest) = (f x, y) : mapFirst f rest | ||
|
||
spec :: SpecWith () | ||
spec = | ||
describe "KeyMap" $ do | ||
it "lookupDefault matches the HashMap implementation" $ | ||
property $ \((fallback :: Text), key, mapping) -> | ||
let keyMapValue = KM.lookupDefault fallback (KM.fromText key) (KM.fromList $ mapFirst KM.fromText mapping) | ||
hashMapValue = HM.lookupDefault fallback key (HM.fromList mapping) | ||
in keyMapValue `shouldBe` hashMapValue |