packages feed

squeeze-1.0.1.4: src/Squeeze/FileSizeBounds.hs

{-
	Copyright (C) 2010 Dr. Alistair Ward

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
-}
{- |
 [@AUTHOR@]	Dr. Alistair Ward

 [@DESCRIPTION@]	Defines a type-synonym for the permissible bounds on the size of a file or set of files, and associated operations.
-}

module Squeeze.FileSizeBounds (
-- * Types
-- ** Type-synonyms
	FileSizeBounds,
-- * Functions
	inside,
	precisely,
	shift
) where

import			Control.Arrow((&&&), (***))
import qualified	Squeeze.File	as File

-- | Used to define the minimum and maximum permissible bounds on the size of a file or set of files.
type FileSizeBounds	= (File.FileSize, File.FileSize)

-- | Predicate.
inside ::
	FileSizeBounds		-- ^ The bounds defining /inside/ from /outside/.
	-> File.FileSize	-- ^ The file-parameters to be tested.
	-> Bool
inside (i, j) x	= ($ x) `all` [(>= i), (<= j)]

-- | Construct the bounds from a single 'FileSize'.
precisely :: File.FileSize -> FileSizeBounds
precisely	= id &&& id

-- | Shift of both bounds by the specified amount.
shift ::
	File.FileSize		-- ^ The magnitude of the require shift.
	-> FileSizeBounds	-- ^ The input set of bounds.
	-> FileSizeBounds
shift i	= (+ i) *** (+ i)