Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chiroptical/derive-has-field
https://github.com/chiroptical/derive-has-field
Last synced: 10 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/chiroptical/derive-has-field
- Owner: chiroptical
- License: mit
- Created: 2023-09-26T21:25:31.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-16T15:47:51.000Z (20 days ago)
- Last Synced: 2024-10-19T01:30:07.775Z (18 days ago)
- Language: Haskell
- Size: 20.5 KB
- Stars: 11
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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