parsonsmatt / prairie

First Class Record Fields in Haskell
BSD 3-Clause "New" or "Revised" License
17 stars 4 forks source link

Semigroups, Monoids, Zips, and `AsRecord` #13

Closed parsonsmatt closed 5 months ago

parsonsmatt commented 5 months ago

This PR introduces Prairie.Semigroup, allowing you to appendRecord :: (Record rec, FieldDict Semigroup rec) => rec -> rec -> rec. We also get Prairie.Monoid, giving you emptyRecord :: (Record rec, FieldDict Monoid rec) => rec. These are pretty self-explanatory.

appendRecord is implemented with zipWithRecord :: (Record rec) => (forall ty. ty -> ty -> Field rec ty -> ty) -> rec -> rec -> rec, also introduced here. This allows you to combine two records with a function specifying how to combine the values.

Finally, we provide AsRecord, a newtype for DerivingVia which lets you derive Monoid and Semigroup instances using the behavior of appendRecord and emptyRecord.

Before submitting your PR, check that you've:

After submitting your PR: