derivingvia-extras: DerivingVia extras - Miscellaneous /via/ types.

[ bsd3, deriving, library, utils ] [ Propose Tags ] [ Report a vulnerability ]

Includes various functionality to use with DerivingVia.

-- >> alice = User "Alice" 50 0xDEADBEAF
-- >> bob   = User "Bob"   20 0xDEADBEAF
-- >>
-- >> alice == bob
-- True
-- >> hash alice == hash bob
-- True
data User = User
  { name   :: String
  , age    :: Int
  , userID :: Integer
  }
  deriving (Eq, Ord, Hashable)
  via User `On` "userID"

[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Change log CHANGELOG.md
Dependencies base (>=4 && <5), hashable [details]
License BSD-3-Clause
Author Baldur Blöndal
Maintainer Baldur Blöndal
Category Deriving, Utils
Bug tracker https://github.com/Icelandjack/derivingvia-extras/issues
Source repo head: git clone https://github.com/Icelandjack/derivingvia-extras
Uploaded by BaldurBlondal at 2022-04-29T00:56:43Z
Distributions NixOS:0.1.0.0
Downloads 122 total (1 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-04-29 [all 1 reports]

Readme for derivingvia-extras-0.1.0.0

[back to package description]

derivingvia-extras

Miscellaneous via types, for use with DerivingVia.

On

The type On T "field" derives non-structural instances for T by comparing an evaluting it only at the record field "field".

{-# Language DataKinds     #-}
{-# Language DerivingVia   #-}
{-# Language TypeOperators #-}

import Deriving.On
import Data.Hashable

data User = User
  { name   :: String
  , age    :: Int
  , userID :: Integer
  }
  deriving (Eq, Ord, Hashable)
  via User `On` "userID"

such that all other fields are ignored

>> alice = User "Alice" 50 0xDEADBEAF
>> bob   = User "Bob"   20 0xDEADBEAF
>>
>> alice == bob
True
>> alice <= bob
True
>> hash alice == hash bob
True