sdp-0.2: Simple Data Processing
Copyright(c) Andrey Mulik 2020
LicenseBSD-style
Maintainerwork.a.mulik@gmail.com
Portabilityportable
Safe HaskellSafe
LanguageHaskell2010

SDP.MapM

Contents

Description

SDP.MapM provides MapM - class of mutable associative arrays.

Synopsis
  • class Monad m => MapM m map key e | map -> m, map -> key, map -> e where
    • newMap :: [(key, e)] -> m map
    • newMap' :: e -> [(key, e)] -> m map
    • getAssocs :: map -> m [(key, e)]
    • (>!) :: map -> key -> m e
    • (!>) :: map -> key -> m e
    • (!?>) :: map -> key -> m (Maybe e)
    • updateM :: map -> (key -> e -> e) -> m map
    • overwrite :: map -> [(key, e)] -> m map
    • memberM' :: map -> key -> m Bool
    • getKeys :: map -> m [key]
    • (.?) :: (e -> Bool) -> map -> m (Maybe key)
    • (*?) :: (e -> Bool) -> map -> m [key]
    • kfoldrM :: (key -> e -> acc -> m acc) -> acc -> map -> m acc
    • kfoldlM :: (key -> acc -> e -> m acc) -> acc -> map -> m acc
    • kfoldrM' :: (key -> e -> acc -> m acc) -> acc -> map -> m acc
    • kfoldlM' :: (key -> acc -> e -> m acc) -> acc -> map -> m acc
  • type MapM1 m map key e = MapM m (map e) key e
  • type MapM2 m map key e = MapM m (map key e) key e

Mutable maps

class Monad m => MapM m map key e | map -> m, map -> key, map -> e where Source #

MapM is class of mutable associative arrays.

Minimal complete definition

newMap', overwrite, ((>!) | (!?>)), kfoldrM, kfoldlM

Methods

newMap :: [(key, e)] -> m map Source #

Create new mutable map from list of (key, element) associations.

newMap' :: e -> [(key, e)] -> m map Source #

Create new mutable map from list of (key, element) associations.

getAssocs :: map -> m [(key, e)] Source #

getAssocs is version of assocs for mutable maps.

default getAssocs :: LinearM m map e => map -> m [(key, e)] Source #

(>!) :: map -> key -> m e infixl 5 Source #

(>!) is unsafe monadic reader.

(!>) :: map -> key -> m e infixl 5 Source #

(!>) is well-safe monadic reader.

default (!>) :: BorderedM m map key => map -> key -> m e Source #

(!?>) :: map -> key -> m (Maybe e) infixl 5 Source #

(!?>) is completely safe monadic reader.

updateM :: map -> (key -> e -> e) -> m map Source #

Update elements by mapping with indices.

overwrite :: map -> [(key, e)] -> m map Source #

This function designed to overwrite large enough fragments of the structure (unlike writeM and writeM')

In addition to write operations, overwrite can move and clean, optimize data presentation, etc. of a particular structure. Since the reference to the original structure may not be the same as reference to the result (which implementation is undesirable, but acceptable), the original reference (argument) shouldn't be used after overwrite.

All standard sdp structures support safe in-place overwrite.

If the structure uses unmanaged memory, then all unused fragments in the resulting structure must be deallocated, regardless of reachability by original reference (argument).

Please note that overwrite require a list of associations with indices in the current structure bounds and ignore any other, therefore:

fromAssocs bnds ascs /= (fromAssocs bnds ascs >>= flip overwrite ascs)

memberM' :: map -> key -> m Bool Source #

Checks if key in map.

default memberM' :: BorderedM m map key => map -> key -> m Bool Source #

getKeys :: map -> m [key] Source #

Returns list of map keys.

default getKeys :: BorderedM m map key => map -> m [key] Source #

(.?) :: (e -> Bool) -> map -> m (Maybe key) Source #

(.?) is monadic version of (.$).

(*?) :: (e -> Bool) -> map -> m [key] Source #

(*?) is monadic version of (*$).

kfoldrM :: (key -> e -> acc -> m acc) -> acc -> map -> m acc Source #

kfoldrM is right monadic fold with key.

kfoldlM :: (key -> acc -> e -> m acc) -> acc -> map -> m acc Source #

kfoldlM is left monadic fold with key.

kfoldrM' :: (key -> e -> acc -> m acc) -> acc -> map -> m acc Source #

kfoldrM' is strict version of kfoldrM.

kfoldlM' :: (key -> acc -> e -> m acc) -> acc -> map -> m acc Source #

kfoldlM' is strict version of kfoldlM.

Instances

Instances details
MapM STM (TArray# e) Int e Source # 
Instance details

Defined in SDP.Prim.TArray

Methods

newMap :: [(Int, e)] -> STM (TArray# e) Source #

newMap' :: e -> [(Int, e)] -> STM (TArray# e) Source #

getAssocs :: TArray# e -> STM [(Int, e)] Source #

(>!) :: TArray# e -> Int -> STM e Source #

(!>) :: TArray# e -> Int -> STM e Source #

(!?>) :: TArray# e -> Int -> STM (Maybe e) Source #

updateM :: TArray# e -> (Int -> e -> e) -> STM (TArray# e) Source #

overwrite :: TArray# e -> [(Int, e)] -> STM (TArray# e) Source #

memberM' :: TArray# e -> Int -> STM Bool Source #

getKeys :: TArray# e -> STM [Int] Source #

(.?) :: (e -> Bool) -> TArray# e -> STM (Maybe Int) Source #

(*?) :: (e -> Bool) -> TArray# e -> STM [Int] Source #

kfoldrM :: (Int -> e -> acc -> STM acc) -> acc -> TArray# e -> STM acc Source #

kfoldlM :: (Int -> acc -> e -> STM acc) -> acc -> TArray# e -> STM acc Source #

kfoldrM' :: (Int -> e -> acc -> STM acc) -> acc -> TArray# e -> STM acc Source #

kfoldlM' :: (Int -> acc -> e -> STM acc) -> acc -> TArray# e -> STM acc Source #

(MonadIO io, Unboxed e) => MapM io (MIOBytes# io e) Int e Source # 
Instance details

Defined in SDP.Prim.SBytes

Methods

newMap :: [(Int, e)] -> io (MIOBytes# io e) Source #

newMap' :: e -> [(Int, e)] -> io (MIOBytes# io e) Source #

getAssocs :: MIOBytes# io e -> io [(Int, e)] Source #

(>!) :: MIOBytes# io e -> Int -> io e Source #

(!>) :: MIOBytes# io e -> Int -> io e Source #

(!?>) :: MIOBytes# io e -> Int -> io (Maybe e) Source #

updateM :: MIOBytes# io e -> (Int -> e -> e) -> io (MIOBytes# io e) Source #

overwrite :: MIOBytes# io e -> [(Int, e)] -> io (MIOBytes# io e) Source #

memberM' :: MIOBytes# io e -> Int -> io Bool Source #

getKeys :: MIOBytes# io e -> io [Int] Source #

(.?) :: (e -> Bool) -> MIOBytes# io e -> io (Maybe Int) Source #

(*?) :: (e -> Bool) -> MIOBytes# io e -> io [Int] Source #

kfoldrM :: (Int -> e -> acc -> io acc) -> acc -> MIOBytes# io e -> io acc Source #

kfoldlM :: (Int -> acc -> e -> io acc) -> acc -> MIOBytes# io e -> io acc Source #

kfoldrM' :: (Int -> e -> acc -> io acc) -> acc -> MIOBytes# io e -> io acc Source #

kfoldlM' :: (Int -> acc -> e -> io acc) -> acc -> MIOBytes# io e -> io acc Source #

MonadIO io => MapM io (MIOArray# io e) Int e Source # 
Instance details

Defined in SDP.Prim.SArray

Methods

newMap :: [(Int, e)] -> io (MIOArray# io e) Source #

newMap' :: e -> [(Int, e)] -> io (MIOArray# io e) Source #

getAssocs :: MIOArray# io e -> io [(Int, e)] Source #

(>!) :: MIOArray# io e -> Int -> io e Source #

(!>) :: MIOArray# io e -> Int -> io e Source #

(!?>) :: MIOArray# io e -> Int -> io (Maybe e) Source #

updateM :: MIOArray# io e -> (Int -> e -> e) -> io (MIOArray# io e) Source #

overwrite :: MIOArray# io e -> [(Int, e)] -> io (MIOArray# io e) Source #

memberM' :: MIOArray# io e -> Int -> io Bool Source #

getKeys :: MIOArray# io e -> io [Int] Source #

(.?) :: (e -> Bool) -> MIOArray# io e -> io (Maybe Int) Source #

(*?) :: (e -> Bool) -> MIOArray# io e -> io [Int] Source #

kfoldrM :: (Int -> e -> acc -> io acc) -> acc -> MIOArray# io e -> io acc Source #

kfoldlM :: (Int -> acc -> e -> io acc) -> acc -> MIOArray# io e -> io acc Source #

kfoldrM' :: (Int -> e -> acc -> io acc) -> acc -> MIOArray# io e -> io acc Source #

kfoldlM' :: (Int -> acc -> e -> io acc) -> acc -> MIOArray# io e -> io acc Source #

(SplitM1 m rep e, MapM1 m rep Int e, BorderedM1 m rep Int e) => MapM m (AnyChunks rep e) Int e Source # 
Instance details

Defined in SDP.Templates.AnyChunks

Methods

newMap :: [(Int, e)] -> m (AnyChunks rep e) Source #

newMap' :: e -> [(Int, e)] -> m (AnyChunks rep e) Source #

getAssocs :: AnyChunks rep e -> m [(Int, e)] Source #

(>!) :: AnyChunks rep e -> Int -> m e Source #

(!>) :: AnyChunks rep e -> Int -> m e Source #

(!?>) :: AnyChunks rep e -> Int -> m (Maybe e) Source #

updateM :: AnyChunks rep e -> (Int -> e -> e) -> m (AnyChunks rep e) Source #

overwrite :: AnyChunks rep e -> [(Int, e)] -> m (AnyChunks rep e) Source #

memberM' :: AnyChunks rep e -> Int -> m Bool Source #

getKeys :: AnyChunks rep e -> m [Int] Source #

(.?) :: (e -> Bool) -> AnyChunks rep e -> m (Maybe Int) Source #

(*?) :: (e -> Bool) -> AnyChunks rep e -> m [Int] Source #

kfoldrM :: (Int -> e -> acc -> m acc) -> acc -> AnyChunks rep e -> m acc Source #

kfoldlM :: (Int -> acc -> e -> m acc) -> acc -> AnyChunks rep e -> m acc Source #

kfoldrM' :: (Int -> e -> acc -> m acc) -> acc -> AnyChunks rep e -> m acc Source #

kfoldlM' :: (Int -> acc -> e -> m acc) -> acc -> AnyChunks rep e -> m acc Source #

(Index i, MapM1 m rep Int e, LinearM1 m rep e, BorderedM1 m rep Int e) => MapM m (AnyBorder rep i e) i e Source # 
Instance details

Defined in SDP.Templates.AnyBorder

Methods

newMap :: [(i, e)] -> m (AnyBorder rep i e) Source #

newMap' :: e -> [(i, e)] -> m (AnyBorder rep i e) Source #

getAssocs :: AnyBorder rep i e -> m [(i, e)] Source #

(>!) :: AnyBorder rep i e -> i -> m e Source #

(!>) :: AnyBorder rep i e -> i -> m e Source #

(!?>) :: AnyBorder rep i e -> i -> m (Maybe e) Source #

updateM :: AnyBorder rep i e -> (i -> e -> e) -> m (AnyBorder rep i e) Source #

overwrite :: AnyBorder rep i e -> [(i, e)] -> m (AnyBorder rep i e) Source #

memberM' :: AnyBorder rep i e -> i -> m Bool Source #

getKeys :: AnyBorder rep i e -> m [i] Source #

(.?) :: (e -> Bool) -> AnyBorder rep i e -> m (Maybe i) Source #

(*?) :: (e -> Bool) -> AnyBorder rep i e -> m [i] Source #

kfoldrM :: (i -> e -> acc -> m acc) -> acc -> AnyBorder rep i e -> m acc Source #

kfoldlM :: (i -> acc -> e -> m acc) -> acc -> AnyBorder rep i e -> m acc Source #

kfoldrM' :: (i -> e -> acc -> m acc) -> acc -> AnyBorder rep i e -> m acc Source #

kfoldlM' :: (i -> acc -> e -> m acc) -> acc -> AnyBorder rep i e -> m acc Source #

Unboxed e => MapM (ST s) (STBytes# s e) Int e Source # 
Instance details

Defined in SDP.Prim.SBytes

Methods

newMap :: [(Int, e)] -> ST s (STBytes# s e) Source #

newMap' :: e -> [(Int, e)] -> ST s (STBytes# s e) Source #

getAssocs :: STBytes# s e -> ST s [(Int, e)] Source #

(>!) :: STBytes# s e -> Int -> ST s e Source #

(!>) :: STBytes# s e -> Int -> ST s e Source #

(!?>) :: STBytes# s e -> Int -> ST s (Maybe e) Source #

updateM :: STBytes# s e -> (Int -> e -> e) -> ST s (STBytes# s e) Source #

overwrite :: STBytes# s e -> [(Int, e)] -> ST s (STBytes# s e) Source #

memberM' :: STBytes# s e -> Int -> ST s Bool Source #

getKeys :: STBytes# s e -> ST s [Int] Source #

(.?) :: (e -> Bool) -> STBytes# s e -> ST s (Maybe Int) Source #

(*?) :: (e -> Bool) -> STBytes# s e -> ST s [Int] Source #

kfoldrM :: (Int -> e -> acc -> ST s acc) -> acc -> STBytes# s e -> ST s acc Source #

kfoldlM :: (Int -> acc -> e -> ST s acc) -> acc -> STBytes# s e -> ST s acc Source #

kfoldrM' :: (Int -> e -> acc -> ST s acc) -> acc -> STBytes# s e -> ST s acc Source #

kfoldlM' :: (Int -> acc -> e -> ST s acc) -> acc -> STBytes# s e -> ST s acc Source #

MapM (ST s) (STArray# s e) Int e Source # 
Instance details

Defined in SDP.Prim.SArray

Methods

newMap :: [(Int, e)] -> ST s (STArray# s e) Source #

newMap' :: e -> [(Int, e)] -> ST s (STArray# s e) Source #

getAssocs :: STArray# s e -> ST s [(Int, e)] Source #

(>!) :: STArray# s e -> Int -> ST s e Source #

(!>) :: STArray# s e -> Int -> ST s e Source #

(!?>) :: STArray# s e -> Int -> ST s (Maybe e) Source #

updateM :: STArray# s e -> (Int -> e -> e) -> ST s (STArray# s e) Source #

overwrite :: STArray# s e -> [(Int, e)] -> ST s (STArray# s e) Source #

memberM' :: STArray# s e -> Int -> ST s Bool Source #

getKeys :: STArray# s e -> ST s [Int] Source #

(.?) :: (e -> Bool) -> STArray# s e -> ST s (Maybe Int) Source #

(*?) :: (e -> Bool) -> STArray# s e -> ST s [Int] Source #

kfoldrM :: (Int -> e -> acc -> ST s acc) -> acc -> STArray# s e -> ST s acc Source #

kfoldlM :: (Int -> acc -> e -> ST s acc) -> acc -> STArray# s e -> ST s acc Source #

kfoldrM' :: (Int -> e -> acc -> ST s acc) -> acc -> STArray# s e -> ST s acc Source #

kfoldlM' :: (Int -> acc -> e -> ST s acc) -> acc -> STArray# s e -> ST s acc Source #

type MapM1 m map key e = MapM m (map e) key e Source #

Rank (* -> *) MapM.

type MapM2 m map key e = MapM m (map key e) key e Source #

Rank (* -> * -> *) MapM.