Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/chiroptical/derive-has-field


https://github.com/chiroptical/derive-has-field

Last synced: 10 days ago
JSON representation

Awesome Lists containing this project

README

        

Derive HasField instances
===

The [`OverloadedRecordDot`][overloaded-record-dot] syntax is surprisingly nice.
I really enjoy writing code with this extension and I was originally hesistant.

[Persistent][persistent] has a really nice feature where it will automatically remove
prefixes from models. Given a model like,

```
BankAccount
accountNumber String
```

You would normally reference this field as `bankAccountAccountNumber`. However,
with overloaded record dot you can write `bankAccount.accountNumber` which is
much nicer.

At work, I really wanted this for **every** record. With this library, I can
write,

```haskell
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TemplateHaskell #-}

import DeriveHasField

data BankAccount =
BankAccount
{ bankAccountAccountNumber :: String
}

deriveHasFieldWith (dropPrefix "bankAccount") ''BankAccount
```

[overloaded-record-dot]: https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/overloaded_record_dot.html
[persistent]: https://github.com/yesodweb/persistent