Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combinator with predicate #237

Closed
vrom911 opened this issue Oct 27, 2019 · 1 comment · Fixed by #286
Closed

Combinator with predicate #237

vrom911 opened this issue Oct 27, 2019 · 1 comment · Fixed by #286
Assignees
Labels
codec Conversion between TOML and custom user data types question Further information is requested

Comments

@vrom911
Copy link
Member

vrom911 commented Oct 27, 2019

Sometimes you need something to be valid only if satisfy the predicate. It would be nice to have such a function in tomland.

Recently I've done the one for Text using textBy function:

https://github.com/kowainik/summoner/blob/2ce94372c0bccaf4adf377814324f6d4fd751366/summoner-cli/src/Summoner/CustomPrelude.hs#L23-L32

However, I don't really see how this could be generalised. Do you have any idea? And do you think that this is generally useful for the library?

@vrom911 vrom911 added question Further information is requested codec Conversion between TOML and custom user data types labels Oct 27, 2019
@chshersh
Copy link
Contributor

@vrom911 That's an excellent idea! I think we should try to implement generalised combinator since it will be the most useful and composable. First idea is something like:

validate :: (a -> Bool) -> Key -> TomlCodec a

or we can use Either Text ... instead of Bool to give an ability to provide better custom errors. But the most general form probably should be somehow be a more polymorphic version of the _TextBy combinator, but it's not clear immediately how to do this, need to think more...

@chshersh chshersh pinned this issue Nov 3, 2019
@chshersh chshersh added this to the v1.3.0.0: Big update milestone May 7, 2020
@vrom911 vrom911 self-assigned this May 16, 2020
@vrom911 vrom911 changed the title [RFC] Combinator with predicate Combinator with predicate May 16, 2020
vrom911 added a commit that referenced this issue May 16, 2020
chshersh pushed a commit that referenced this issue May 16, 2020
* [#237] Combinator with predicate

Resolves #237

* Fix
@vrom911 vrom911 unpinned this issue May 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codec Conversion between TOML and custom user data types question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants