Skip to content

Latest commit

 

History

History
27 lines (21 loc) · 828 Bytes

README.org

File metadata and controls

27 lines (21 loc) · 828 Bytes

omit-generics

omit-generics aims to make deriving Eq and Ord instances easier by giving the programmer control over what fields to ignore.

This is best explained by an example:

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DerivingVia #-}

import GHC.Generics
import GHC.Generics.Omit

data Person = Person { name :: String, age :: Int, metadata :: [String] }
    deriving stock Generic
    deriving Eq via (Omit '["age", "metadata"] Person)

Now, when we compare Person for equality, the age and metadata fields are ignored!

Person "Steve" 43 ["loves cats"] == Person "Steve" 1 ["loves dogs", "is a baby"]
> True