keera-hails-reactivelenses 0.0.1 → 0.8.0
raw patch · 6 files changed
+316/−55 lines, 6 filesdep +HUnitdep +QuickCheckdep +directorynew-uploaderPVP ok
version bump matches the API change (PVP)
Dependencies added: HUnit, QuickCheck, directory, filepath, hlint, mtl, process, regex-posix, tasty, tasty-hunit, tasty-quickcheck
API changes (from Hackage documentation)
Files
- LICENSE +5/−4
- keera-hails-reactivelenses.cabal +134/−44
- src/Data/ReactiveLens.hs +15/−7
- tests/HLintMain.hs +23/−0
- tests/HaddockCoverage.hs +88/−0
- tests/Tasty.hs +51/−0
LICENSE view
@@ -1,4 +1,5 @@-Copyright (c)2012, Ivan Perez+Copyright (c) 2013-2020, Keera Studios Ltd+Copyright (c) 2010-2012, Ivan Perez All rights reserved. @@ -13,9 +14,9 @@ disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Ivan Perez nor the names of other- contributors may be used to endorse or promote products derived- from this software without specific prior written permission.+ * Neither the name of Ivan Perez, nor the name of Keera Studios, 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
keera-hails-reactivelenses.cabal view
@@ -1,62 +1,152 @@--- hails.cabal auto-generated by cabal init. For additional options,--- see--- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.--- The name of the package.-Name: keera-hails-reactivelenses+-- Copyright : (C) Keera Studios Ltd, 2013+-- License : All Rights Reserved+-- Maintainer : support@keera.co.uk+--+cabal-version: >= 1.10+build-type: Simple --- The package version. See the Haskell package versioning policy--- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for--- standards guiding when and how versions should be incremented.-Version: 0.0.1+name: keera-hails-reactivelenses+version: 0.8.0+author: Ivan Perez+maintainer: support@keera.co.uk+homepage: http://www.keera.co.uk/blog/community/+license: BSD3+license-file: LICENSE+copyright: (C) 2013 Keera Studios Ltd+category: Development+synopsis: Reactive Haskell on Rails - Lenses applied to Reactive Values+description:+ Keera Hails is a rapid application development system.+ .+ The idea behind Hails is that you should be able to build cross platform+ applications with minimal effort, very quickly, and the result should be easy+ to maintain.+ .+ Large Hails applications are structured following an optimized MVC+ architecture. Values are updated either from the view to the model, or from+ the model to the view. Internally, rules use a notion of direction in the+ update to determine how different components must be updated.+ .+ This library provides a way to use lenses to focus on a specific+ part of a reactive value. --- A short (one-line) description of the package.-Synopsis: Reactive Haskell on Rails - Lenses applied to Reactive Values+source-repository head+ type: git+ location: git://github.com/keera-studios/keera-hails+ subdir: keera-hails-reactivelenses --- A longer description of the package.--- Description:+-- You can disable the hlint test suite with -f-test-hlint+flag test-hlint+ default: True+ manual: True --- URL for the project homepage or repository.-Homepage: http://www.keera.es/blog/community/+-- You can disable the haddock coverage test suite with -f-test-doc-coverage+flag test-doc-coverage+ default: True+ manual: True --- The license under which the package is released.-License: BSD3+flag test-unit-tests+ default: True+ manual: True --- The file containing the license text.-License-file: LICENSE+library --- The package author(s).-Author: Ivan Perez+ exposed-modules:+ Data.ReactiveLens --- An email address to which users can send suggestions, bug reports,--- and patches.-Maintainer: ivan.perez@keera.es+ build-depends:+ base >= 4 && < 5+ , lens --- A copyright notice.--- Copyright:+ , keera-hails-reactivevalues -Category: Development+ default-language:+ Haskell2010 -Build-type: Simple+ hs-source-dirs:+ src/ --- Extra files to be distributed with the package, such as examples or--- a README.--- Extra-source-files:+ ghc-options:+ -Wall -fno-warn-unused-do-bind -O2 --- Constraint on the version of Cabal needed to build this package.-Cabal-version: >= 1.6 -Library- hs-source-dirs: src/+test-suite hlint - ghc-options: -Wall -fno-warn-unused-do-bind+ type:+ exitcode-stdio-1.0 - -- Modules exported by the library.- Exposed-modules: Data.ReactiveLens+ main-is:+ HLintMain.hs - -- Packages needed in order to build this package.- Build-depends: base >= 4 && < 5, lens, keera-hails-reactivevalues+ default-language:+ Haskell2010 -source-repository head- type: git- location: git://github.com/keera-studios/keera-hails- subdir: keera-hails-reactivelenses+ hs-source-dirs:+ tests++ if !flag(test-hlint)+ buildable: False+ else+ build-depends:+ base >= 4 && < 5+ , hlint >= 1.7++-- Verify that the code is thoroughly documented+test-suite haddock-coverage++ type:+ exitcode-stdio-1.0++ main-is:+ HaddockCoverage.hs++ default-language:+ Haskell2010++ hs-source-dirs:+ tests++ ghc-options:+ -Wall++ if !flag(test-doc-coverage)+ buildable: False+ else+ build-depends:+ base >= 4 && < 5+ , directory+ , filepath+ , process+ , regex-posix++test-suite unit-tests++ type:+ exitcode-stdio-1.0++ main-is:+ Tasty.hs++ default-language:+ Haskell2010++ hs-source-dirs:+ tests++ ghc-options:+ -Wall++ if !flag(test-unit-tests)+ buildable: False+ else+ build-depends:+ base >= 4 && < 5+ , mtl++ , keera-hails-reactivevalues++ , tasty+ , tasty-quickcheck+ , tasty-hunit+ , QuickCheck+ , HUnit
src/Data/ReactiveLens.hs view
@@ -1,16 +1,24 @@ {-# LANGUAGE Rank2Types #-}+-- | Apply lenses onto Reactive Values, produced RVs that focus+-- only on a part of the value.+--+-- Copyright : (C) Keera Studios Ltd, 2013+-- License : BSD3+-- Maintainer : support@keera.co.uk module Data.ReactiveLens where import Control.Lens import Data.ReactiveValue +-- | Apply a lens to a reactive value, produced another reactive value that+-- focuses on a part of the first. reactiveFromLens :: (Monad m, Functor m) => ReactiveFieldReadWrite m a -> Lens' a b -> ReactiveFieldReadWrite m b-reactiveFromLens (ReactiveFieldReadWrite setter getter notifier) l =- ReactiveFieldReadWrite setter' getter' notifier- where setter' v = setter.(set l v) =<< getter+reactiveFromLens rv@(ReactiveFieldReadWrite _setter getter notifier) l =+ ReactiveFieldReadWrite setter' getter' notifier+ where setter' v = reactiveValueModify rv (set l v) getter' = fmap (view l) getter -- I'd love to write this, but it's not possible because Haskell does not@@ -24,10 +32,10 @@ -- equivalente definition: 'flip' 'reactiveFromLens'. (<$$$>) :: (Monad m, Functor m) => Lens' a b -> ReactiveFieldReadWrite m a -> ReactiveFieldReadWrite m b-(<$$$>) l (ReactiveFieldReadWrite setter getter notifier) =- ReactiveFieldReadWrite setter' getter' notifier- where setter' v = setter.(set l v) =<< getter- getter' = fmap (view l) getter+(<$$$>) l rv@(ReactiveFieldReadWrite _setter getter notifier) =+ ReactiveFieldReadWrite setter' getter' notifier+ where setter' v = reactiveValueModify rv (set l v)+ getter' = fmap (view l) getter -- I think this bit would need monadic lenses -- reactiveLens :: Lens' a b -> Lens' (ReactiveFieldReadWrite m a) (ReactiveFieldReadWrite m b)
+ tests/HLintMain.hs view
@@ -0,0 +1,23 @@+-----------------------------------------------------------------------------+-- |+-- Module : Main (hlint)+-- Copyright : (C) 2015 Ivan Perez, 2013-2014 Edward Kmett+-- License : BSD-style (see the file LICENSE)+-- Maintainer : Ivan Perez <ivan.perez@keera.co.uk>+-- Stability : provisional+-- Portability : portable+--+-- This module runs HLint on the source tree.+-----------------------------------------------------------------------------+module Main where++import Control.Monad+import Language.Haskell.HLint+import System.Environment+import System.Exit++main :: IO ()+main = do+ args <- getArgs+ hints <- hlint $ ["src"] ++ args+ unless (null hints) exitFailure
+ tests/HaddockCoverage.hs view
@@ -0,0 +1,88 @@+-----------------------------------------------------------------------------+-- |+-- Module : Main (HaddockCoverage)+-- Copyright : (C) 2015 Ivan Perez+-- License : BSD-style (see the file LICENSE)+-- Maintainer : Ivan Perez <ivan.perez@keera.co.uk>+-- Stability : provisional+-- Portability : portable+--+-- Copyright notice: This file borrows code+-- https://hackage.haskell.org/package/lens-4.7/src/tests/doctests.hsc+-- which is itself licensed BSD-style as well.+--+-- Run haddock on a source tree and report if anything in any+-- module is not documented.+-----------------------------------------------------------------------------+module Main where++import Control.Applicative+import Control.Monad+import Data.List+import System.Directory+import System.Exit+import System.FilePath+import System.IO+import System.Process+import Text.Regex.Posix++main :: IO ()+main = do+ -- Find haskell modules+ -- TODO: Ideally cabal should do this (provide us with the+ -- list of modules). An alternative would be to use cabal haddock+ -- but that would need a --no-html argument or something like that.+ -- Alternatively, we could use cabal haddock with additional arguments.+ --+ -- See:+ -- https://github.com/keera-studios/haddock/commit/d5d752943c4e5c6c9ffcdde4dc136fcee967c495+ -- https://github.com/haskell/haddock/issues/309#issuecomment-150811929+ files <- getSources++ let haddockArgs = [ "--no-warnings" ] ++ files+ let cabalArgs = [ "exec", "--", "haddock" ] ++ haddockArgs+ (code, out, _err) <- readProcessWithExitCode "cabal" cabalArgs ""++ -- Filter out coverage lines, and find those that denote undocumented+ -- modules.+ --+ -- TODO: is there a way to annotate a function as self-documenting,+ -- in the same way we do with ANN for hlint?+ let isIncompleteModule :: String -> Bool+ isIncompleteModule line = isCoverageLine line && not (line =~ "^ *100%")+ where isCoverageLine :: String -> Bool+ isCoverageLine line = line =~ "^ *[0-9]+%"++ let incompleteModules :: [String]+ incompleteModules = filter isIncompleteModule $ lines out++ -- Based on the result of haddock, report errors and exit.+ -- Note that, unline haddock, this script does not+ -- output anything to stdout. It uses stderr instead+ -- (as it should).+ case (code, incompleteModules) of+ (ExitSuccess , []) -> return ()+ (ExitFailure _, _) -> exitFailure+ (_ , _) -> do+ hPutStrLn stderr "The following modules are not fully documented:"+ mapM_ (hPutStrLn stderr) incompleteModules+ exitFailure++getSources :: IO [FilePath]+getSources = filter isHaskellFile <$> go "src"+ where+ go dir = do+ (dirs, files) <- getFilesAndDirectories dir+ (files ++) . concat <$> mapM go dirs++ isHaskellFile fp = isSuffixOf ".hs" fp || isSuffixOf ".lhs" fp++getFilesAndDirectories :: FilePath -> IO ([FilePath], [FilePath])+getFilesAndDirectories dir = do+ c <- map (dir </>) . filter (`notElem` ["..", "."]) <$> getDirectoryContents dir+ (,) <$> filterM doesDirectoryExist c <*> filterM doesFileExist c++-- find-based implementation (not portable)+--+-- getSources :: IO [FilePath]+-- getSources = fmap lines $ readProcess "find" ["src/", "-iname", "*hs"] ""
+ tests/Tasty.hs view
@@ -0,0 +1,51 @@+-----------------------------------------------------------------------------+-- |+-- Module : Main (Tasty)+-- Copyright : (C) 2015 Ivan Perez+-- License : BSD-style (see the file LICENSE)+-- Maintainer : Ivan Perez <ivan.perez@keera.co.uk>+-- Stability : provisional+-- Portability : portable+--+-- Test reactive value laws with lenses using Quickcheck/HUnit/Tasty.+--+-- See the following links for instructions and documentation:+-- https://github.com/feuerbach/tasty+-- https://ocharles.org.uk/blog/posts/2013-12-03-24-days-of-hackage-tasty.html+-----------------------------------------------------------------------------++-- Testing libraries+import Test.Tasty+import Test.Tasty.QuickCheck+-- import Test.QuickCheck+-- import Test.Tasty.HUnit++-- Tested libraries+import Control.Monad.Identity+import Data.ReactiveValue++main :: IO ()+main = defaultMain $+ testGroup "ReactiveValues"+ [ testGroup "GetSetLaws"+ [ testProperty "Getting after constant initialisation" getOnConst+ ]+ ]++-- * Reactive Value laws++-- ** Reactive Value get/set laws++-- | Check that constR returns the value put in.+getOnConst :: Int -> Bool+getOnConst =+ \val -> let rv = constR (val :: Int)+ val' = runIdentity (reactiveValueRead rv)+ in val == val'++-- NOTE: To check that the testing system and the integration with cabal are+-- both working fine, you can use include this property in one of the tested+-- groups; the test suite should fail.+-- falseProperty =+-- testProperty "False" $+-- \val -> not (val == (val :: Int))