A purescript library for cherry-picking π your data.
Ehh, wat ?
Morello is a library for making data transformation and validation super simple.
Transform & validate your input data in a declarative way.
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
lenses
to zoom into your input dataSee MinimalSpec for a short example that illustrates the basic functionality.
See usage guide
Contributions via issues & PRs are very welcome.
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
, heterogeneous
and validation
libraries. This library wouldn't have been possible without these.
Licensed under MIT-0.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4