-- | This module provides the ability to append two records using '(<>)',
-- provided that all of their fields have an instance of 'Semigroup'.
module Prairie.Semigroup where

import Prairie.Class
import Prairie.Zip

-- | Zip two records together using a 'Semigroup' append.
--
-- @since 0.0.4.0
appendRecord
    :: forall rec. (Record rec, FieldDict Semigroup rec)
    => rec
    -> rec
    -> rec
appendRecord :: forall rec.
(Record rec, FieldDict Semigroup rec) =>
rec -> rec -> rec
appendRecord =
    (forall ty. ty -> ty -> Field rec ty -> ty) -> rec -> rec -> rec
forall rec.
Record rec =>
(forall ty. ty -> ty -> Field rec ty -> ty) -> rec -> rec -> rec
zipWithRecord (\ty
a ty
b Field rec ty
field -> forall (c :: Type -> Constraint) rec a r.
FieldDict c rec =>
Field rec a -> (c a => r) -> r
withFieldDict @Semigroup Field rec ty
field (ty
a ty -> ty -> ty
forall a. Semigroup a => a -> a -> a
<> ty
b))