Idris2Doc : Libraries.Data.WithData

Libraries.Data.WithData

(source)
The WithData module combines a record and an arbitrary payload. The intended use is to
attach metadata to the payload.

Reexports

importpublic Data.List.Quantifiers
importpublic Data.List
importpublic Data.Maybe
importpublic Libraries.Data.Record

Definitions

recordWithData : ListKeyVal->Type->Type
  A pair for a type and an attached record hosting metadata about that type

Intended usage
--------------
Only ever put plain types in the metadata
Do not add functors such as `List` or `PTerm`. The functor instance
for `WithData` is only functorial on its payload and not the metadata.

There is rarely any need to write down `WithData [ ... ] a` thanks to the
`AddMetadata` type constructor.

While possible, you are not meant to pattern match on values of this type
to extract the main payload, you can use the `val` projection, and to access
metadata fields you can use `get` and `getAt` functions that will automatically
compute and extract the value out of the metadata record.

Example usage
-------------
Given a value of type `value : WithData ["loc" :-: Location, "cached" :-: Bool] Term`
we can access the `Term` by projecting our the underlying value:
```idris example
termValue : Term
termValue = value.val
```
To access the metadata fields use `get` with the name of the field or `getAt` with
the index of the field. For example "loc" is at index `0` therefore one can access
it using `getAt 0`:
```idris example
termLocation : Location
termLocation = value `getAt` 0
```
Similarly, we can obtain the "cached" field by giving its name directly
```idris example
termCache : Bool
termCache = value.get "cached"
```

Totality: total
Visibility: public export
Constructor: 
MkWithData : Recordadditional->payload->WithDataadditionalpayload

Projections:
.metadata : WithDataadditionalpayload->Recordadditional
.val : WithDataadditionalpayload->payload

Hints:
All (Eq.type) fs=>Eqa=>Eq (WithDatafsa)
Functor (WithDatamd)
All (TTC.type) fs=>TTCa=>TTC (WithDatafsa)
.metadata : WithDataadditionalpayload->Recordadditional
Visibility: public export
metadata : WithDataadditionalpayload->Recordadditional
Visibility: public export
.val : WithDataadditionalpayload->payload
Visibility: public export
val : WithDataadditionalpayload->payload
Visibility: public export
AddMetadata : KeyVal->Type->Type
  Add some metadata to a type given a label and a type for the metadata
This function matches on the type and add it to the metadata record if it is alread a `WithData`

example:
```idris example
Term : Type

RichTerm : Type
RichTerm = AddMetadata ("loc" :-: Location) $ AddMetadata ("cached" :-: Bool) Term
```
The example shows how to add the fields "loc" and "cached" to the type `Term` as metadata. Those
fields can be accessed with `get` and `getAt` functions

Visibility: public export
getAt : (ix : Nat) -> {auto0_ : FindIndexixfields=Justout} ->WithDatafieldsa->out
  Obtain the value of the metadata at the given index
@ ix The index of the value we are extracting
@ inRange A proof the index is in range of the metadata record

Visibility: export
get : (0label : String) -> {auto0_ : NameInRangelabelfields=Just (n, out)} ->WithDatafieldsa->out
  Obtain the value out of the payload record given its label, same as `(.get)`
@ label The label of the value we are extracting
@ inRange A proof that the label is in the record at the appropriate index with the appropriate type.

Visibility: export
.get : WithDatafieldsa-> (0field : String) -> {auto0_ : NameInRangefieldfields=Just (n, out)} ->out
  Obtain the value out of the payload record given its label, same as `get`.
@ label The label of the value we are extracting.
@ inRange A proof that the label is in the record at the appropriate index with the appropriate type.

Visibility: export
updateAt : (ix : Nat) ->FindIndexixfields=Justout=> (out->out) ->WithDatafieldsa->WithDatafieldsa
  Update at the given index, updates cannot change the type of the field.
@ ix The index at which we update the value.
@ inRange A proof that the index is in range of the metadata record.
@ f The update function.

Visibility: export
update : (0label : String) -> {auto0_ : NameInRangelabelfields=Just (n, out)} -> (out->out) ->WithDatafieldsa->WithDatafieldsa
  Update the value with the given field name
@ label The label of the value we are updating
@ inRange A proof that the label is in the record at the appropriate index with the appropriate type.
@ f The update function.

Visibility: export
setAt : (n : Nat) ->FindIndexnls=Justout=>out->WithDatalsa->WithDatalsa
  Override the value at the given index.
@ n The index at which we replace our value.
@ inRange A proof that index is in range.
@ newVal The new value remplacing the existing one.

Visibility: export
set : (0label : String) -> {auto0_ : NameInRangelabells=Just (n, out)} ->out->WithDatalsa->WithDatalsa
  Override the value matching the given label
@ label The label of the value we are overriding.
@ inRange A proof that the label is in the record at the appropriate index with the appropriate type.
@ newVal The new value remplacing the existing one.

Visibility: export
Add : (0lbl : String) ->ty->a->WithData [(lbl:-:ty)] a
  Add a labelled value to the metadata

Visibility: export
(:+) : ty->WithDatalsa->WithData ((lbl:-:ty) ::ls) a
  Add value the payload, ignore the label since it's given by the type

Visibility: export
Fixity Declaration: infixr operator, level 9
drop : WithData (l::ls) a->WithDatalsa
  Drop the head element of the metadata

Visibility: export
.drop : WithData (l::ls) a->WithDatalsa
  Drop the head element of the metadata

Visibility: export
interfaceHasDefault : Type->Type
  An interface for default values, used to fill in missing values in metadata records

Parameters: a
Methods:
defValue : a

Implementations:
HasDefaultFC
HasDefaultBindingModifier
HasDefaultString
defValue : HasDefaulta=>a
Visibility: public export
MkDef : a->All (HasDefault.type) fs=>WithDatafsa
  Construct a payload filled with default values for its metadata

Visibility: export
Mk : Alltypefs->a->WithDatafsa
  Construct a value with metadata but ignore the labels

Visibility: export
AddDef : HasDefaultty=>WithDatafla->WithData ((lbl:-:ty) ::fl) a
  Add a default value to an existing metadata record

Visibility: export
distribData : WithDatafs (Lista) ->List (WithDatafsa)
Visibility: export
distribDataMaybe : WithDatafs (Maybea) ->Maybe (WithDatafsa)
Visibility: export
traverseDataMaybe : (a->Maybeb) ->WithDatafsa->Maybe (WithDatafsb)
Visibility: export