Module
Record.ExtraSrghma.MapValuesWithIndex
- Package
- purescript-record-extra-srghma
- Repository
- srghma/purescript-record-extra-srghma
#mapValuesWithIndex Source
mapValuesWithIndex :: forall row rowList a b row'. RowToList row rowList => MapValuesWithIndex rowList row a b () row' => (String -> a -> b) -> Record row -> Record row'
Like mapRecord
from https://github.com/justinwoo/purescript-record-extra
but mapRecordWithIndex
The 'mapValuesWithIndex' function allows you to transform the values of a record,
with access to the index (as the field name) and the value.
Example usage:
let record = { name: "Alice", age: 25 }
let result = mapValuesWithIndex (\name value -> name ++ ": " ++ show value) record
-- result will be: { name: "name: Alice", age: "age: 25" }
#MapValuesWithIndex Source
class MapValuesWithIndex :: RowList Type -> Row Type -> Type -> Type -> Row Type -> Row Type -> Constraint
class MapValuesWithIndex (rowList :: RowList Type) (row :: Row Type) a b (from :: Row Type) (to :: Row Type) | rowList -> row a b from to where
Type class for transforming record values based on field names and values.
Members
Instances
(IsSymbol fieldName, Cons fieldName a restRow row, MapValuesWithIndex tail row a b from from', Lacks fieldName from', Cons fieldName b from' to) => MapValuesWithIndex (Cons fieldName a tail) row a b from to
Instance for transforming a record with a non-empty field (i.e., head of the row list).
MapValuesWithIndex Nil row a b () ()
Base case: Empty record (i.e., no fields to transform).
- Modules
- Record.
ExtraSrghma - Record.
ExtraSrghma. AppendRecord - Record.
ExtraSrghma. CompareRecord - Record.
ExtraSrghma. FoldlValues - Record.
ExtraSrghma. FoldlValuesWithIndex - Record.
ExtraSrghma. FoldrValues - Record.
ExtraSrghma. FoldrValuesLazy - Record.
ExtraSrghma. FoldrValuesWithIndex - Record.
ExtraSrghma. Keys. Array - Record.
ExtraSrghma. Keys. List - Record.
ExtraSrghma. Keys. NonEmptyArray - Record.
ExtraSrghma. Keys. NonEmptyList - Record.
ExtraSrghma. Keys. Pick - Record.
ExtraSrghma. MapIndex - Record.
ExtraSrghma. MapRecord - Record.
ExtraSrghma. MapValuesWithIndex - Record.
ExtraSrghma. ParSequenceRecord - Record.
ExtraSrghma. SList. Array - Record.
ExtraSrghma. SList. List - Record.
ExtraSrghma. SList. Types - Record.
ExtraSrghma. SequenceRecord - Record.
ExtraSrghma. TraverseRecord - Record.
ExtraSrghma. ValuesToUnfoldableLazy - Record.
ExtraSrghma. ZipRecord
The implementation for mapping over the record's values with the field name.