composite-ix (empty) → 0.0.1.0
raw patch · 7 files changed
+216/−0 lines, 7 filesdep +basedep +composite-basedep +containers
Dependencies added: base, composite-base, containers, lens, nonempty-containers, vector, vinyl
Files
- ChangeLog.md +6/−0
- LICENSE +30/−0
- README.md +1/−0
- composite-ix.cabal +54/−0
- src/Composite/Ix/List.hs +41/−0
- src/Composite/Ix/NonEmpty.hs +42/−0
- src/Composite/Ix/Vector.hs +42/−0
+ ChangeLog.md view
@@ -0,0 +1,6 @@+# Changelog for composite-ix++## 0.0.1.0++* Added module `Composite.Ix.Vector`.+* Added modules `Composite.Ix.List` and `Composite.Ix.NonEmpty`.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Author name here (c) 2022++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,1 @@+# composite-ix
+ composite-ix.cabal view
@@ -0,0 +1,54 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.34.6.+--+-- see: https://github.com/sol/hpack++name: composite-ix+version: 0.0.1.0+synopsis: Indexing utilities for composite records.+description: Indexing utilities for composite records.+category: Web+author: Daniel Firth+maintainer: dan.firth@homotopic.tech+copyright: 2022 Daniel Firth+license: BSD3+license-file: LICENSE+build-type: Simple+extra-source-files:+ README.md+ ChangeLog.md++source-repository head+ type: git+ location: https://gitlab.homotopic.tech/haskell/composite-ix++library+ exposed-modules:+ Composite.Ix.List+ Composite.Ix.NonEmpty+ Composite.Ix.Vector+ other-modules:+ Paths_composite_ix+ hs-source-dirs:+ src+ default-extensions:+ AllowAmbiguousTypes+ DeriveGeneric+ DerivingStrategies+ FlexibleContexts+ GADTs+ RankNTypes+ ScopedTypeVariables+ StandaloneDeriving+ TypeApplications+ TypeOperators+ build-depends:+ base >=4.7 && <5+ , composite-base+ , containers+ , lens+ , nonempty-containers+ , vector+ , vinyl+ default-language: Haskell2010
+ src/Composite/Ix/List.hs view
@@ -0,0 +1,41 @@+module Composite.Ix.List (groupBy, groupBy', groupBy'') where++import Composite.Record+import Control.Lens+import qualified Data.Map as M+import Data.Proxy+import Data.Vinyl hiding (rlens, rlens')+import Prelude++-- | Group a list of records by a subtype of the record type.+--+-- @since 0.0.1.0+groupBy :: forall ys xs f.+ (ys ⊆ xs)+ => Ord (Rec f ys)+ => [Rec f xs]+ -> M.Map (Rec f ys) [Rec f xs]+groupBy xs = M.fromListWith (<>) $ fmap (\x -> (rcast x, [x])) xs++-- | Group a list of records by a single field.+--+-- @since 0.0.1.0+groupBy' :: forall k s y xs.+ k ~ (s :-> y)+ => k ∈ xs+ => Ord y+ => [Record xs]+ -> M.Map y [Record xs]+groupBy' xs = M.fromListWith (<>) $ fmap (\x -> (view (rlens (Proxy @(s :-> y))) x, [x])) xs++-- | Group a list of records by a single field (HKD).+--+-- @since 0.0.1.0+groupBy'' :: forall k s y xs f.+ k ~ (s :-> y)+ => k ∈ xs+ => Functor f+ => Ord (f y)+ => [Rec f xs]+ -> M.Map (f y) [Rec f xs]+groupBy'' xs = M.fromListWith (<>) $ fmap (\x -> (view (rlens' (Proxy @(s :-> y))) x, [x])) xs
+ src/Composite/Ix/NonEmpty.hs view
@@ -0,0 +1,42 @@+module Composite.Ix.NonEmpty (groupBy, groupBy', groupBy'') where++import Composite.Record+import Control.Lens+import Data.List.NonEmpty (NonEmpty ((:|)))+import qualified Data.List.NonEmpty as NE+import qualified Data.Map.NonEmpty as MNE+import Data.Proxy+import Data.Vinyl hiding (rlens, rlens')++-- | Group a NonEmpty list of records by a subtype of the record.+--+-- @since 0.0.1.0+groupBy :: forall ys xs f.+ (ys ⊆ xs)+ => Ord (Rec f ys)+ => NonEmpty (Rec f xs)+ -> MNE.NEMap (Rec f ys) (NonEmpty (Rec f xs))+groupBy xs = MNE.fromListWith (<>) $ fmap (\x -> (rcast x, x :| [])) xs++-- | Group a NonEmpty list of records by a single field.+--+-- @since 0.0.1.0+groupBy' :: forall k s y xs.+ k ~ (s :-> y)+ => k ∈ xs+ => Ord y+ => NonEmpty (Record xs)+ -> MNE.NEMap y (NonEmpty (Record xs))+groupBy' xs = MNE.fromListWith (<>) $ fmap (\x -> (view (rlens (Proxy @(s :-> y))) x, x :| [])) xs++-- | Group a NonEmpty list of records by a single field (HKD).+--+-- @since 0.0.1.0+groupBy'' :: forall k s y xs f.+ k ~ (s :-> y)+ => k ∈ xs+ => Functor f+ => Ord (f y)+ => NonEmpty (Rec f xs)+ -> MNE.NEMap (f y) (NonEmpty (Rec f xs))+groupBy'' xs = MNE.fromListWith (<>) $ fmap (\x -> (view (rlens' (Proxy @(s :-> y))) x, x :| [])) xs
+ src/Composite/Ix/Vector.hs view
@@ -0,0 +1,42 @@+module Composite.Ix.Vector (groupBy, groupBy', groupBy'') where++import Composite.Record+import Control.Lens+import qualified Data.Map as M+import Data.Proxy+import Data.Vector as V (Vector, singleton, toList)+import Data.Vinyl hiding (rlens, rlens')+import Prelude++-- | Group a vector of records by a subtype of the record type.+--+-- @since 0.0.1.0+groupBy :: forall ys xs f.+ (ys ⊆ xs)+ => Ord (Rec f ys)+ => Vector (Rec f xs)+ -> M.Map (Rec f ys) (Vector (Rec f xs))+groupBy xs = M.fromListWith (<>) $ V.toList $ fmap (\x -> (rcast x, V.singleton x)) xs++-- | Group a vector of records by a single field.+--+-- @since 0.0.1.0+groupBy' :: forall k s y xs.+ k ~ (s :-> y)+ => k ∈ xs+ => Ord y+ => Vector (Record xs)+ -> M.Map y (Vector (Record xs))+groupBy' xs = M.fromListWith (<>) $ V.toList $ fmap (\x -> (view (rlens (Proxy @(s :-> y))) x, V.singleton x)) xs++-- | Group a vector of records by a single field (HKD).+--+-- @since 0.0.1.0+groupBy'' :: forall k s y xs f.+ k ~ (s :-> y)+ => k ∈ xs+ => Functor f+ => Ord (f y)+ => Vector (Rec f xs)+ -> M.Map (f y) (Vector (Rec f xs))+groupBy'' xs = M.fromListWith (<>) $ V.toList $ fmap (\x -> (view (rlens' (Proxy @(s :-> y))) x, V.singleton x)) xs