packages feed

base16-lens (empty) → 0.1.0.0

raw patch · 8 files changed

+264/−0 lines, 8 filesdep +basedep +base16dep +base16-lensbuild-type:Customsetup-changed

Dependencies added: base, base16, base16-lens, bytestring, doctest, lens, text

Files

+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# Revision history for base64-lens++## 0.1.0.0++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2020, Emily Pillmore++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 Emily Pillmore 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,34 @@+# Base16-lens++[![Build Status](https://travis-ci.com/emilypi/base16-lens.svg?branch=master)](https://travis-ci.com/emilypi/base16-lens)+[![Hackage](https://img.shields.io/hackage/v/base16-lens.svg)](https://hackage.haskell.org/package/base16-lens)++This package provides optics and convenient pattern synonyms for the [base16](https://hackage.haskell.org/package/base16) library.++### Patterns++The pattern synonyms provided in this library are:++```haskell+pattern Hex :: ByteString -> ByteString+-- and+pattern Hex :: Text -> Text+```++These provide a convenient high level interface for passing Base16 encoded values.+++### Optics++`Prism`s for encoding and decoding `Text` and `ByteString` values are given as part of the library:+++```haskell+_Hex :: Prism' ByteString ByteString++-- and++_Hex:: Prism' Text Text+```++If a particular structure has a `Lens` into some `Text` or `ByteString` value they might want to encode (or decode), then composing such a `Lens` with these `Prisms` yields an affine `Traversal`, resulting in a structure which has the focus of its `Lens` encoded as or decoded from Base16.
+ Setup.hs view
@@ -0,0 +1,6 @@+module Main where++import Distribution.Extra.Doctest (defaultMainWithDoctests)++main :: IO ()+main = defaultMainWithDoctests "doctests"
+ base16-lens.cabal view
@@ -0,0 +1,60 @@+cabal-version:      1.24+name:               base16-lens+version:            0.1.0.0+synopsis:           Optics for the Base16 library+description:        Prisms and pattern synonyms for the Base16 library+homepage:           https://github.com/emilypi/base16-lens+bug-reports:        https://github.com/emilypi/base16-lens/issues+license:            BSD3+license-file:       LICENSE+author:             Emily Pillmore+maintainer:         emilypi@cohomolo.gy+copyright:          (c) 2020 Emily Pillmore+category:           Data+build-type:         Custom+extra-source-files:+  CHANGELOG.md+  README.md++tested-with:+  GHC ==8.2.2 || ==8.4.3 || ==8.4.4 || ==8.6.3 || ==8.6.5 || ==8.8.1++source-repository head+  type:     git+  location: https://github.com/emilypi/base16.git++custom-setup+  setup-depends:+      base           >=4.10 && <5+    , Cabal+    , cabal-doctest++library+  exposed-modules:+    Data.ByteString.Base16.Lens+    Data.Text.Encoding.Base16.Lens++  build-depends:+      base        >=4.10   && <5+    , base16      >= 0.1.1 && <0.2+    , bytestring  >=0.10   && <0.11+    , lens        >=4.0    && <5+    , text        >=1.2    && <1.3++  hs-source-dirs:   src+  default-language: Haskell2010+  ghc-options:      -Wall++test-suite doctests+  default-language:  Haskell2010+  type:              exitcode-stdio-1.0+  main-is:           doctests.hs+  build-depends:+      base         >=4.10 && <5+    , base16-lens+    , doctest+    , lens++  hs-source-dirs:    test+  ghc-options:       -Wall -threaded+  x-doctest-options: --fast
+ src/Data/ByteString/Base16/Lens.hs view
@@ -0,0 +1,62 @@+{-# LANGUAGE PatternSynonyms #-}+{-# LANGUAGE ViewPatterns #-}+-- |+-- Module       : Data.Text.Encoding.Base16.Lens+-- Copyright 	: (c) 2019 Emily Pillmore+-- License	: BSD-style+--+-- Maintainer	: Emily Pillmore <emilypi@cohomolo.gy>+-- Stability	: Experimental+-- Portability	: non-portable+--+-- This module contains 'Prism''s for Base16-encoding and+-- decoding 'ByteString' values.+--+module Data.ByteString.Base16.Lens+( -- * Prisms+  _Hex+  -- * Patterns+, pattern Hex+) where+++import Control.Lens++import Data.ByteString (ByteString)+import qualified Data.ByteString.Base16 as B16+++-- $setup+--+-- >>> import Control.Lens+-- >>> import Data.ByteString.Base16.Lens+--+-- >>> :set -XOverloadedStrings+-- >>> :set -XTypeApplications+++-- -------------------------------------------------------------------------- --+-- Optics++-- | A 'Prism'' into the Base16 encoding of a 'ByteString' value+--+-- >>> _Hex # "Sun"+-- "53756e"+--+-- >>> "53756e" ^? _Hex+-- Just "Sun"+--+_Hex :: Prism' ByteString ByteString+_Hex = prism' B16.encodeBase16' $ \s -> case B16.decodeBase16 s of+    Left _ -> Nothing+    Right a -> Just a+{-# INLINE _Hex #-}++-- -------------------------------------------------------------------------- --+-- Patterns++-- | Bidirectional pattern synonym for Base16-encoded 'ByteString' values.+--+pattern Hex :: ByteString -> ByteString+pattern Hex a <- (preview _Hex -> Just a) where+    Hex a = _Hex # a
+ src/Data/Text/Encoding/Base16/Lens.hs view
@@ -0,0 +1,60 @@+{-# LANGUAGE PatternSynonyms #-}+{-# LANGUAGE ViewPatterns #-}+-- |+-- Module       : Data.Text.Encoding.Base16.Lens+-- Copyright 	: (c) 2020 Emily Pillmore+-- License	: BSD-style+--+-- Maintainer	: Emily Pillmore <emilypi@cohomolo.gy>+-- Stability	: Experimental+-- Portability	: non-portable+--+-- This module contains 'Prism's Base16-encoding and+-- decoding 'Text' values.+--+module Data.Text.Encoding.Base16.Lens+( -- * Prisms+  _Hex+  -- * Patterns+, pattern Hex+) where++import Control.Lens++import Data.Text (Text)+import qualified Data.Text.Encoding.Base16 as B16T+++-- $setup+--+-- >>> import Control.Lens+-- >>> import Data.Text.Encoding.Base16.Lens+--+-- >>> :set -XOverloadedStrings+-- >>> :set -XTypeApplications++-- -------------------------------------------------------------------------- --+-- Optics++-- | A 'Prism'' into the Base16 encoding of a 'Text' value+--+-- >>> _Hex # "Sun"+-- "53756e"+--+-- >>> "53756e" ^? _Hex+-- Just "Sun"+--+_Hex :: Prism' Text Text+_Hex = prism' B16T.encodeBase16 $ \s -> case B16T.decodeBase16 s of+    Left _ -> Nothing+    Right a -> Just a+{-# INLINE _Hex #-}++-- -------------------------------------------------------------------------- --+-- Patterns++-- | Bidirectional pattern synonym for Base16-encoded 'Text' values.+--+pattern Hex :: Text -> Text+pattern Hex a <- (preview _Hex -> Just a) where+    Hex a = _Hex # a
+ test/doctests.hs view
@@ -0,0 +1,7 @@+module Main where++import Build_doctests (flags, pkgs, module_sources)+import Test.DocTest (doctest)++main :: IO ()+main = doctest $ flags ++ pkgs ++ module_sources