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

Infix operator alias for Lens.compose #11

Closed
Bastes opened this issue Dec 3, 2017 · 6 comments
Closed

Infix operator alias for Lens.compose #11

Bastes opened this issue Dec 3, 2017 · 6 comments

Comments

@Bastes
Copy link
Contributor

Bastes commented Dec 3, 2017

I really love monocle and the ability to use lenses to get and set values easily.

But since lenses are especially interesting when you can compose them, and since composition can be deep for deeply nested structures, it's a bit annoying and counter-intuitive to have to do this:

lens1 : Lens a b
lens2 : Lens b c
lens3 : Lens c d

lens13_1 : Lens a d
lens13_1 =
  lens3
    |> compose lens2
    |> compose lens1

-- OR

lens13_2 : Lens a d
lens13_2 =
  compose (compose lens1 lens2) lens3

-- OR

lens13_3 : Lens a d
lens13_3 =
  let
    lens12 = compose lens1 lens2
  in
    compose lens12 lens3

-- OR EVEN
lens13_4 : Lens a d
lens13_4 =
  compose lens1 <| compose lens2 lens3

All these patterns are grating to read. We usually solved it making "half-way" lenses like:

lens12 = compose lens1 lens2
lens13 = compose lens12 lens3

But I can't help thinking we might benefit from an infix Lens.compose alias allowing to do things like:

(<|>) = Lens.compose
lens13 = lens1 <|> lens2 <|> lens3

(I've actually done it in projects of my own that use lenses)

So, what do you think?

@arturopala
Copy link
Owner

arturopala commented Dec 3, 2017 via email

@Bastes
Copy link
Contributor Author

Bastes commented Dec 3, 2017 via email

@Bastes
Copy link
Contributor Author

Bastes commented Dec 10, 2017

Here, finally took time to implement it 😄

@Bastes
Copy link
Contributor Author

Bastes commented Dec 11, 2017

(sorry, it appears I have forgotten to bump the version up 😅 I'm fairly new to publishing packages in elm -completely new in fact- should I send you another pull request with the new version? I'm reading this can be done automatically using "elm-package bump", but I don't want to do something that'd mess with your repo)

@Bastes
Copy link
Contributor Author

Bastes commented Dec 11, 2017

I just tried the elm-package bump and it seems to have done the job ; hence the new PR #13

@Bastes
Copy link
Contributor Author

Bastes commented Dec 19, 2017

(and I guess we can close this now anyways ^^° sorry for not being very responsive the last few days)

@Bastes Bastes closed this as completed Dec 19, 2017
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

No branches or pull requests

2 participants