An open API service indexing awesome lists of open source software.

https://github.com/totbwf/omit-generics

Omit fields for instance deriving
https://github.com/totbwf/omit-generics

ghc-generics haskell

Last synced: about 1 month ago
JSON representation

Omit fields for instance deriving

Awesome Lists containing this project

README

        

* 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:
#+BEGIN_SRC haskell :multi-line t
{-# 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)
#+END_SRC

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

#+BEGIN_SRC haskell
Person "Steve" 43 ["loves cats"] == Person "Steve" 1 ["loves dogs", "is a baby"]
> True
#+END_SRC