packages feed

within (empty) → 0.0.1.0

raw patch · 6 files changed

+148/−0 lines, 6 filesdep +basedep +exceptionsdep +pathsetup-changed

Dependencies added: base, exceptions, path

Files

+ ChangeLog.md view
@@ -0,0 +1,8 @@+# Changelog for within++## v0.0.1.o++* Add Within Type based on [path](https://hackage.haskell.org/package/path).+Within is a path within another path.+* Add several functions for moving between directories and mapping source+  names.
+ 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,8 @@+# Within++`Within` is a type for simply scoping well-typed paths. A `Within a t` is+just a `Path Rel t` inside a `Path a Dir`. This is useful for when you want+to keep track of a filepath within a parent folder and need the extra degree+of articulation.++Early release, subject to change.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Within.hs view
@@ -0,0 +1,65 @@+{-# LANGUAGE DeriveGeneric #-}+module Within (+  Within(..)+, fromWithin+, toWithin+, within+, asWithin+, whatLiesWithin+, mapWithin+, mapWithinT+, moveWithin+, moveWithinT+, blinkWithin+, moveAndMapT+, blinkAndMapT+) where++import Control.Monad.Catch+import Data.Typeable+import GHC.Generics+import Path++newtype Within a t = Within (Path a Dir, Path Rel t)+  deriving (Typeable, Generic, Eq, Show)++fromWithin :: Within a t -> Path a t+fromWithin (Within (x,y)) = x </> y++toWithin :: Path a Dir -> Path Rel t -> Within a t+toWithin = flip within++within :: Path Rel t -> Path a Dir -> Within a t+within y x = Within (x,y)++asWithin :: MonadThrow m => Path a t -> Path a Dir -> m (Within a t)+asWithin x y = stripProperPrefix y x >>= \z -> return (Within (y, z))++whatLiesWithin :: Within a t -> Path Rel t+whatLiesWithin (Within (_,y)) = y++mapWithin :: (Path Rel s -> Path Rel t) -> Within a s -> Within a t+mapWithin f (Within (x,y)) = Within (x, f y)++mapWithinT :: MonadThrow m => (Path Rel s -> m (Path Rel t)) -> Within a s -> m (Within a t)+mapWithinT f (Within (x,y)) = f y >>= \z -> return (Within (x, z))++blinkWithin :: Path b Dir -> Within a t -> Within b t+blinkWithin = moveWithin . const++moveWithin :: (Path a Dir -> Path b Dir) -> Within a t -> Within b t+moveWithin f (Within (x,y)) = Within (f x, y)++moveWithinT :: MonadThrow m => (Path a Dir -> m (Path b Dir)) -> Within a t -> m (Within b t)+moveWithinT f (Within (x,y)) = f x >>= \z -> return (Within (z,y))++blinkAndMapT :: MonadThrow m => Path b Dir -> (Path Rel s -> m (Path Rel t)) -> Within a s -> m (Within b t)+blinkAndMapT k g (Within (_,y)) = do+  y' <- g y+  return $ Within (k, y')++moveAndMapT :: MonadThrow m => (Path a Dir -> m (Path b Dir)) -> (Path Rel s -> m (Path Rel t)) -> Within a s -> m (Within b t)+moveAndMapT f g (Within (x,y)) = do+  x' <- f x+  y' <- g y+  return $ Within (x', y')
+ within.cabal view
@@ -0,0 +1,35 @@+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: b387258ad76af8d3a2c66d14e6c7814a0c5b23ceabe75719dbbb8aae3e8a6bde++name:           within+version:        0.0.1.0+synopsis:       A path within another path.+description:    Simple type for representing a well-typed path within another path. Useful for when you need to jump between directories and change filenames independently. Uses the path library.+category:       Filesystem+author:         Daniel Firth+maintainer:     dan.firth@homotopic.tech+copyright:      2020 Daniel Firth+license:        MIT+license-file:   LICENSE+build-type:     Simple+extra-source-files:+    README.md+    ChangeLog.md++library+  exposed-modules:+      Within+  other-modules:+      Paths_within+  hs-source-dirs:+      src+  build-depends:+      base >=4.7 && <5+    , exceptions+    , path+  default-language: Haskell2010