fields-0.1.0: First-class record field combinators with infix record field syntax.



Composition operators for collection fields.



class Indexable a i whereSource

Class of collection types that can be indexed into.

TODO: This should probably be a single-parameter type class with two associated types instead.

Associated Types

type Element a :: *Source


indexGet :: i -> a -> Maybe (Element a)Source

indexSet :: i -> Maybe (Element a) -> a -> aSource

unsafeIndexGet :: i -> a -> Element aSource


Indexable IntSet Int 
Integral i => Indexable [a] i 
Indexable (IntMap a) Int 
(a1 ~ a2, Ord a1) => Indexable (Set a1) a2 
(i1 ~ i2, IArray a e, Ix i1) => Indexable (a i1 e) i2 
(k1 ~ k2, Ord k1) => Indexable (Map k1 a) k2 

(#!) :: (Field a, Indexable (Dst a) i) => a -> i -> Src a :-> Maybe (Element (Dst a))Source

Compose a field with an Indexable collection safely.

 r .# coll #! idx

returns Nothing if idx was not found from the collection, and Just v if v was found.

 r .# coll #! idx =: Just v

sets the value at idx in the collection to be v. If the value wasn't in the collection, it's inserted. The exact semantics of insertion depend on the actual collection in question.

 r .# coll #! idx =: Nothing

removes the value at idx from the collection, if possible.

(#!!) :: (Field a, Indexable (Dst a) i) => a -> i -> Src a :-> Element (Dst a)Source

As (#!), but reading a nonexistent value will likely result in a bottom value being returned. Also, the resulting field cannot be used to remove values.