packages feed

trek-lens (empty) → 0.0.1.0

raw patch · 7 files changed

+157/−0 lines, 7 filesdep +basedep +lensdep +logictsetup-changed

Dependencies added: base, lens, logict, mtl, trek, trek-lens

Files

+ ChangeLog.md view
@@ -0,0 +1,3 @@+# Changelog for lens-trek++## Unreleased changes
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Author name here (c) 2020++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 Author name here 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,3 @@+# lens-trek++Optics extensions to [Trek](https://github.com/ChrisPenner/trek).
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Trek/Lens.hs view
@@ -0,0 +1,59 @@+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE AllowAmbiguousTypes #-}+module Trek.Lens (+    selecting+    , mounting+    , focusing+    , (%>)+    )+    where++import Control.Lens+import Trek+import Control.Monad.State+import Control.Monad.Logic++-- infixr 4 <+@>+-- (<+@>) :: (Indexable i p, Contravariant f, Applicative f) => IndexedFold i s a -> IndexedFold i s a -> p a (f a) -> s -> f s+-- fldA <+@> fldB = conjoined (fldA <+> fldB) (ifolding (\s -> (s ^@.. fldA) <> (s ^@.. fldB)))++-- infixr 4 <+>+-- -- | (<+>) allows you to append multiple folds into one+-- (<+>) :: Fold s a -> Fold s a -> Fold s a+-- fldA <+> fldB = (folding (\s -> (s ^.. fldA) <> (s ^.. fldB)))++-- | Optical version of 'select'/'selectEach'. Iterates over all result(s) of the provided optic in the structure.+-- Accepts a Getter, Traversal, Prism, Iso or Fold.+selecting :: Monad m => Fold s a -> TrekT s m a+selecting fld = selectEach (toListOf fld)++-- | Allows sequencing a tuple or list of Trek blocks into the values that they return.+-- selectAll :: Monad m => Each x y (TrekT s m b) b => x -> TrekT s m y+-- selectAll = sequenceAOf each++-- | The optical version of 'mount'/'mountEach'. Runs a 'TrekT' block over each focus of+-- the provided optic.+-- All state updates are discarded.+mounting :: Monad m => Fold t s -> TrekT s m a -> TrekT t m a+mounting fld exp = do+    xs <- collect (selecting fld)+    withEach xs exp++infixr 4 `focusing`++-- | Run a 'TrekT' block over a subset of your state. Unlike 'using', updates to the state+-- are KEPT.+focusing :: forall s t m a. (Monad m) => Traversal' s t -> TrekT t m a -> TrekT s m a+focusing trav (TrekT logt) = do+    let st = observeAllT logt+    let zst :: StateT s m [a] = zoom trav st+    xs <- TrekT (lift zst)+    iter xs++-- Infix alias for 'focusing'+infixr 4 %>+-- | Zoom a trek through a traversal+(%>) :: forall m s t a. Monad m => Traversal' s t -> TrekT t m a -> TrekT s m a+(%>) = focusing
+ test/Spec.hs view
@@ -0,0 +1,2 @@+main :: IO ()+main = putStrLn "Test suite not yet implemented"
+ trek-lens.cabal view
@@ -0,0 +1,58 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.33.0.+--+-- see: https://github.com/sol/hpack+--+-- hash: 76c3786ba97f09e1e670ee48b1bf36e9c44debe98bb9719b62bf8d485d2f759d++name:           trek-lens+version:        0.0.1.0+description:    Please see the README on GitHub at <https://github.com/githubuser/trek-lens#readme>+homepage:       https://github.com/githubuser/trek-lens#readme+bug-reports:    https://github.com/githubuser/trek-lens/issues+author:         Author name here+maintainer:     example@example.com+copyright:      2020 Author name here+license:        BSD3+license-file:   LICENSE+build-type:     Simple+extra-source-files:+    README.md+    ChangeLog.md++source-repository head+  type: git+  location: https://github.com/githubuser/trek-lens++library+  exposed-modules:+      Trek.Lens+  other-modules:+      Paths_trek_lens+  hs-source-dirs:+      src+  build-depends:+      base >=4.7 && <5+    , lens+    , logict+    , mtl+    , trek+  default-language: Haskell2010++test-suite trek-lens-test+  type: exitcode-stdio-1.0+  main-is: Spec.hs+  other-modules:+      Paths_trek_lens+  hs-source-dirs:+      test+  ghc-options: -threaded -rtsopts -with-rtsopts=-N+  build-depends:+      base >=4.7 && <5+    , lens+    , logict+    , mtl+    , trek+    , trek-lens+  default-language: Haskell2010