Skip to content

Add applicative operator #4

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

Merged
merged 1 commit into from
Oct 20, 2016
Merged

Add applicative operator #4

merged 1 commit into from
Oct 20, 2016

Conversation

Lysxia
Copy link
Contributor

@Lysxia Lysxia commented Oct 11, 2016

I think this new (=.) allows to create Codecs for records neatly without Template Haskell.

Example:

-- As if    data (,) a b = (,) { fst :: a, snd :: b }

parsePair :: Codec fr fw a -> Codec fr fw b -> Codec fr fw (a, b)
parsePair a b
  = (,)
  <$> fst =. a
  <*> snd =. b

parseFlipped :: Codec fr fw b -> Codec fr fw a -> Codec fr fw (a, b)
parseFlipped b a
  = flip (,)
  <$> snd =. b
  <*> fst =. a

If you agree with this I can try to document it in Data.Codec.

(.=) seems to be the most common choice to map fields in other serialization libraries (JSON, YAML), and I picked the hardly used (=.) to avoid conflicts (assuming that users of Codec might need to use one of these other libraries at the same time).

@Lysxia
Copy link
Contributor Author

Lysxia commented Oct 13, 2016

What do you think of adding a Profunctor instance as well?

@chpatrick chpatrick merged commit 585475a into chpatrick:master Oct 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants