map-exts: Extensions for Data.Map

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Please see README.md


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.1.0.0, 0.1.0.1, 0.1.1.0, 0.2.0.0
Change log None available
Dependencies base (>=4.7 && <5), bytestring, cassava, containers [details]
License BSD-3-Clause
Copyright 2016 Elsen, Inc
Author Charles Cooper
Maintainer cooper.charles.m@gmail.com
Category Data Structures
Home page http://github.com/elsen-trading/map-extensions#readme
Uploaded by coopercm at 2016-04-14T21:45:51Z

Modules

[Index]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for map-exts-0.1.0.0

[back to package description]

map-extensions

This module contains some extensions to Data.Map. Some of them are convenience functions.

It also contains functions to support a split-apply-combine workflow, by representing labeled, multi-dimensional data as multiply nested Maps. For instance, a two dimensional matrix with one axis indexed by 'Name's and the other axis labeled by 'Job's, we would represent such a structure with a Lookup2 Name Job Double. Such a structure is not terribly efficient (it takes O(n log(n)) space and O(log(n)) time for insert/update/delete operations with high constant factor owing to all the pointer manipulation), but it is expressive.

split : groupMapBy apply : fmap combine : foldr/foldMap reshape : transpose

Say we had a dataFrame :: (Lookup2 Name Job Age). We could group by Job by running transpose on it. If we wanted to find the average Age in a job, we could define

mean :: Map k v -> Int
mean xs = foldr (+) 0 xs / Map.size xs

type Name = String
type Job  = String
type Age  = Double
averageAgeInJob :: Lookup2 Name Job Age -> Map Job Age
averageAgeInJob dataFrame = fmap mean $ transpose dataFrame

This illustrates applying an aggregation over a particular index by reshaping with transpose, defining a fold, and then focusing it inside the structure using fmap.