purescript-iso (empty) → 0.0.0
raw patch · 9 files changed
+196/−0 lines, 9 filesdep +QuickCheckdep +aesondep +basesetup-changed
Dependencies added: QuickCheck, aeson, base, purescript-iso
Files
- ChangeLog.md +3/−0
- LICENSE +30/−0
- README.md +1/−0
- Setup.hs +2/−0
- purescript-iso.cabal +56/−0
- src/Data/Aeson/JSONEither.hs +38/−0
- src/Data/Aeson/JSONTuple.hs +30/−0
- src/Data/Aeson/JSONUnit.hs +34/−0
- test/Spec.hs +2/−0
+ ChangeLog.md view
@@ -0,0 +1,3 @@+# Changelog for purescript-iso++## Unreleased changes
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Athan Clark (c) 2018++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Athan Clark nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,1 @@+# purescript-iso
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ purescript-iso.cabal view
@@ -0,0 +1,56 @@+-- This file has been generated from package.yaml by hpack version 0.21.2.+--+-- see: https://github.com/sol/hpack+--+-- hash: de96d00ba8e2fb7e53006e20f819121ac9341d70202233d317ccb59507c7e678++name: purescript-iso+version: 0.0.0+synopsis: Isomorphic trivial data type definitions over JSON+description: Please see the README on GitHub at <https://github.com/githubuser/purescript-iso#readme>+category: Web+author: Athan Clark+maintainer: athan.clark@localcooking.com+copyright: 2018 (c) Local Cooking Inc.+license: BSD3+license-file: LICENSE+build-type: Simple+cabal-version: >= 1.10++extra-source-files:+ ChangeLog.md+ README.md++source-repository head+ type: git+ location: git://git.localcooking.com/tooling/purescript-iso.git++library+ exposed-modules:+ Data.Aeson.JSONEither+ Data.Aeson.JSONTuple+ Data.Aeson.JSONUnit+ other-modules:+ Paths_purescript_iso+ hs-source-dirs:+ src+ build-depends:+ QuickCheck+ , aeson+ , base >=4.7 && <5+ default-language: Haskell2010++test-suite purescript-iso-test+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ other-modules:+ Paths_purescript_iso+ hs-source-dirs:+ test+ ghc-options: -threaded -rtsopts -with-rtsopts=-N+ build-depends:+ QuickCheck+ , aeson+ , base >=4.7 && <5+ , purescript-iso+ default-language: Haskell2010
+ src/Data/Aeson/JSONEither.hs view
@@ -0,0 +1,38 @@+{-# LANGUAGE+ OverloadedStrings+ #-}++module Data.Aeson.JSONEither where++import Data.Aeson (ToJSON (..), FromJSON (..), Value (Object), object, (.=), (.:))+import Data.Aeson.Types (typeMismatch)+import Control.Applicative ((<|>))+import Test.QuickCheck (Arbitrary (..))+import Test.QuickCheck.Gen (oneof)+++data JSONEither a b+ = JSONLeft a+ | JSONRight b+ deriving (Eq, Show)++instance (ToJSON a, ToJSON b) => ToJSON (JSONEither a b) where+ toJSON x = case x of+ JSONLeft a -> object ["e" .= a]+ JSONRight b -> object ["x" .= b]++instance (FromJSON a, FromJSON b) => FromJSON (JSONEither a b) where+ parseJSON json = case json of+ Object o -> do+ let e = JSONLeft <$> o .: "e"+ x = JSONRight <$> o .: "x"+ e <|> x+ _ -> fail'+ where+ fail' = typeMismatch "JSONEither" json++instance (Arbitrary a, Arbitrary b) => Arbitrary (JSONEither a b) where+ arbitrary = oneof+ [ JSONLeft <$> arbitrary+ , JSONRight <$> arbitrary+ ]
+ src/Data/Aeson/JSONTuple.hs view
@@ -0,0 +1,30 @@+{-# LANGUAGE+ OverloadedStrings+ #-}++module Data.Aeson.JSONTuple where++import Data.Aeson (ToJSON (..), FromJSON (..), Value (Object), object, (.=), (.:))+import Data.Aeson.Types (typeMismatch)+import Test.QuickCheck (Arbitrary (..))+++data JSONTuple a b = JSONTuple a b+ deriving (Eq, Show)++instance (ToJSON a, ToJSON b) => ToJSON (JSONTuple a b) where+ toJSON (JSONTuple a b) = object ["l" .= a, "r" .= b]++instance (FromJSON a, FromJSON b) => FromJSON (JSONTuple a b) where+ parseJSON json = case json of+ Object o -> JSONTuple <$> o .: "l" <*> o .: "r"+ _ -> fail'+ where+ fail' = typeMismatch "JSONTuple" json++instance (Arbitrary a, Arbitrary b) => Arbitrary (JSONTuple a b) where+ arbitrary = JSONTuple <$> arbitrary <*> arbitrary+++uncurryJSONTuple :: (a -> b -> c) -> JSONTuple a b -> c+uncurryJSONTuple f (JSONTuple a b) = f a b
+ src/Data/Aeson/JSONUnit.hs view
@@ -0,0 +1,34 @@+{-# LANGUAGE+ OverloadedStrings+ #-}++module Data.Aeson.JSONUnit where++import Data.Aeson (ToJSON (..), FromJSON (..), Value (String))+import Data.Aeson.Types (typeMismatch)+++data JSONUnit = JSONUnit+ deriving (Eq, Show)++instance ToJSON JSONUnit where+ toJSON JSONUnit = String ""++instance FromJSON JSONUnit where+ parseJSON json = case json of+ String x+ | x == "" -> pure JSONUnit+ | otherwise -> fail'+ _ -> fail'+ where+ fail' = typeMismatch "JSONUnit" json+++boolToUnit :: Bool -> Maybe JSONUnit+boolToUnit ok+ | ok = Just JSONUnit+ | otherwise = Nothing+++unitToUnit :: () -> Maybe JSONUnit+unitToUnit () = Just JSONUnit
+ test/Spec.hs view
@@ -0,0 +1,2 @@+main :: IO ()+main = putStrLn "Test suite not yet implemented"