Improve showEntities
I have check the last commit from @ad-si where he added showEntity function. I saw a pattern, and started to rewrite it to more maintainable form.
Goals:
- [x] Remove lambda.
- [x] Add Show function for each Entity attribute.
- [ ] Move newline adding from "Entity attribute" functions.
- [ ] Use
fromMaybeonly ones.
My changes didn't break any tests. But I didn't check manually, so I maybe break some format (tests for showEntites use only zeroes, no coverage for other than Id attributes).
This is my first contribution to this project and I can share you my experience with it.
There is no CONTRIBUTING file (I expect its link in README), so I have no exact instruction to follow. Without it I have to manually search for testing tools. After I found command for running tests, I run it before any changes, and it shows me "51/55 tests passed", and "1 test pending" ๐คจ. After my changes I opened this PR (without opening related Issue, that is one of CONTRIBUTING things I check for).
Here is the list of things I think can improve contributors experience:
- CONTRIBUTING file.
- Tests passing status.
- Issue types (and should it be created before PR).
I hope this summary can help this project.
Sorry for claiming there is no CONTRIBUTING, I just found development.md. I found test commands here, but no info about contributing. I think this development.md need to be renamed to CONTRIBUTING.md or be mentioned in README.
My last two goals is to remove repeating logic with fromMaybe and <> "\n", but fixing this I do code like:
showEntity :: Entity -> String
showEntity (Entity entity) =
[ entity.id # showId # Just
, entity.name <#> showName
, entity.note <#> showNote
, entity.utc <#> showUTC
, entity.tags <#> showTags
, entity.accounts <#> showAccounts
]
<#> (map (_ <> "\n"))
<#> fromMaybe ""
# fold
<> "\n"
I think this one looks not as understandable as current one. Or it is just for me?
<#> (map (_ <> "\n")) <#> fromMaybe "" can be replaced with <#> maybe "" (_ <> "\n"), but I am not sure this will improve readability. Can this code be improved in terms of readability?
I think this one looks not as understandable as current one. Or it is just for me?
It can also be that way:
showEntity :: Entity -> String
showEntity (Entity entity) =
[ entity.id # Just
, entity.name
, entity.note
, entity.utc
, entity.tags
, entity.accounts
]
<#> map withNewline
<#> showOrEmpty
# fold
# withNewline
showOrEmpty :: Show s => Maybe s -> String
showOrEmpty (Maybe a) = show a
showOrEmpty Nothing = ""
withNewline :: String -> String
withNewline = _ <> "\n"
@ad-si can you check this?
Thanks a lot for the suggestions!
- I renamed the
development.mdfile tocontributing.md - I included your changes in a7f5aa1a16c4c4b045a4fefd91c30a7deee2cedd (Sorry, for not merging your branch, but it had conflicts and I needed to clean up the code)