control-block (empty) → 0.0.0
raw patch · 4 files changed
+134/−0 lines, 4 filesdep +basedep +containersdep +indexed-traversable
Dependencies added: base, containers, indexed-traversable
Files
- CHANGELOG.md +6/−0
- LICENSE +26/−0
- control-block.cabal +38/−0
- lib/Control/Block.hs +64/−0
+ CHANGELOG.md view
@@ -0,0 +1,6 @@+# Revision history for blocks++## 0.0.0 -- 2023-04-11++* Names for common higher-order functions where the function argument is final,+ allowing easier use of `-XBlockArguments`.
+ LICENSE view
@@ -0,0 +1,26 @@+Copyright (c) 2023, Melanie Phoenix+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are+met:++1. Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++2. 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.++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.
+ control-block.cabal view
@@ -0,0 +1,38 @@+cabal-version: 3.0+name: control-block+version: 0.0.0+license: BSD-2-Clause+license-file: LICENSE+author: Melanie Phoenix Brown+maintainer: brown.m@proton.me+category: Control+build-type: Simple+extra-doc-files: CHANGELOG.md+synopsis:+ Higher-order functions with their function arguments at the end++library+ ghc-options: -Wall+ hs-source-dirs: lib+ default-language: GHC2021+ default-extensions:+ BlockArguments+ DataKinds+ DefaultSignatures+ DerivingStrategies+ FunctionalDependencies+ LambdaCase+ MultiWayIf+ OverloadedStrings+ PatternSynonyms+ QuasiQuotes+ RecordWildCards+ TypeFamilies+ ViewPatterns++ build-depends:+ , base >=4.14 && <5+ , containers+ , indexed-traversable++ exposed-modules: Control.Block
+ lib/Control/Block.hs view
@@ -0,0 +1,64 @@+module Control.Block (+ -- * Functor+ (<$>),+ (<&>),+ fmap,+ imap,+ change,+ ichange,++ -- * Foldable+ foldMap,+ ifoldMap,+ reduce,+ reduceL,+ reduceR,+ ireduce,+ ifor_,+ itraverse_,++ -- * Traversable+ traverse,+ itraverse,+ for,+ ifor,++ -- * Monad+ bind,+ ibind,+) where++import Control.Monad (join)+import Data.Foldable (foldl')+import Data.Foldable.WithIndex (FoldableWithIndex (ifoldMap), ifor_, itraverse_)+import Data.Functor ((<&>))+import Data.Functor.WithIndex (FunctorWithIndex (imap))+import Data.Traversable (for)+import Data.Traversable.WithIndex (TraversableWithIndex (itraverse), ifor)++change :: (Functor f) => f x -> (x -> y) -> f y+change = (<&>)++ichange :: (FunctorWithIndex i f) => f x -> (i -> x -> y) -> f y+ichange = flip imap++-- reduce1 :: (Foldable1 t, Semigroup s) => t x -> (x -> s) -> s+-- reduce1 = flip foldMap1++reduce :: (Foldable t, Monoid m) => t x -> (x -> m) -> m+reduce = flip foldMap++ireduce :: (FoldableWithIndex i t, Monoid m) => t x -> (i -> x -> m) -> m+ireduce = flip ifoldMap++reduceL :: (Foldable t) => y -> t x -> (y -> x -> y) -> y+reduceL = flip . flip foldl'++reduceR :: (Foldable t) => y -> t x -> (x -> y -> y) -> y+reduceR = flip . flip foldr++bind :: (Monad f) => f x -> (x -> f y) -> f y+bind = (>>=)++ibind :: (FunctorWithIndex i f, Monad f) => f x -> (i -> x -> f y) -> f y+ibind = (join .) . ichange