Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sigma-andex/purescript-morello
Cherry-picking π for your data
https://github.com/sigma-andex/purescript-morello
data-transformation data-validation purescript
Last synced: 8 days ago
JSON representation
Cherry-picking π for your data
- Host: GitHub
- URL: https://github.com/sigma-andex/purescript-morello
- Owner: sigma-andex
- License: mit-0
- Created: 2021-02-13T14:43:22.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-11-08T14:54:12.000Z (about 2 years ago)
- Last Synced: 2024-12-09T10:54:51.657Z (14 days ago)
- Topics: data-transformation, data-validation, purescript
- Language: PureScript
- Homepage:
- Size: 142 KB
- Stars: 12
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# purescript-morello πΈ
A purescript library for cherry-picking π your data.
*Ehh, wat ?*
Morello is a library for making data transformation and validation super simple.
## tl;dr
Transform & validate your input data in a declarative way.```purescript
import Morello.Morello-- Given an input model...
type PersonInput = { profession :: { title :: String, salary :: Number } }-- ...and an output model...
type PersonOutput = { details :: { title :: Title, salary :: Salary, jobType :: JobType } }-- ...write some validators...
validateTitle :: Validate String Title
validateTitle "Software Engineer" = invalid (FieldInvalid "Software Engineering is not a serious profession")
validateTitle s = valid (Title s)validateSalary :: Validate Number Salary
validateSalary n
| n > 50000.0 = valid (Salary n)
validateSalary n = invalid (FieldInvalid "Salary is too damn low")-- ...and create a conversion in a declarative way..
convert :: PersonInput -> Validated PersonOutput
convert =
branch
>>> cherry {
-- ...by defining how your output data will look like...
details : {
title:
-- ...picking data from the input record using a lens...
pick' (key :: _ "profession.title") validateTitle :: Pick PersonInput Title
, salary:
-- ...and validating it using validators.
pick' (key :: _ "profession.salary") validateSalary :: Pick PersonInput Salary
, jobType : Worker
}
}
>>> blossom
```## Features
- π **Declarative data conversion:** Define how your output data should look like instead of how to transform the input data
- π **Applicative error accumulation:** Morello collects all validation erros instead of failing on the first error
- πͺ’ **Fully composable**: Cherries are just functions and therefore compose
- π **Lens support**: Use [`lenses`](https://github.com/purescript-contrib/purescript-profunctor-lenses) to zoom into your input data
- πΊοΈ **Unicode support**: Define branches π±, cherries π and blossoms πΈ using unicode## Installation
```bash
spago install morello
```## Quick start
See [MinimalSpec](./test/Morello/Morello/MinimalSpec.purs) for a short example that illustrates the basic functionality.
## Usage
See [usage guide](./docs/usage-guide.md)
## Contributing
Contributions via issues & PRs are very welcome.
## Acknowledgements
This work is merely connecting the dots of the amazing Purescript language and its awesome ecosystem. A special shout-out to the contributors & maintainers of the [`profunctor-lenses`](https://github.com/purescript-contrib/purescript-profunctor-lenses), [`heterogeneous`](https://github.com/natefaubion/purescript-heterogeneous/) and [`validation`](https://github.com/purescript/purescript-validation) libraries. This library wouldn't have been possible without these.
## License
Licensed under [MIT-0](LICENSE).