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

Add convenience function to get year from Day #267

Open
mchav opened this issue Dec 22, 2024 · 3 comments
Open

Add convenience function to get year from Day #267

mchav opened this issue Dec 22, 2024 · 3 comments

Comments

@mchav
Copy link

mchav commented Dec 22, 2024

Given a Day you can get the year, month, and day as a tuple by writing fromGregorian day. Getting the year requires pattern matching on a 3-tuple or using lens' to get the first field. I think it's a common enough operation that it might be worth defining a convenience function called gregorianYear or year in the Gregorian package.

@mchav mchav changed the title Add convenience function to get year DAy Add convenience function to get year from Day Dec 22, 2024
@AshleyYakeley
Copy link
Member

You can just use the YearMonthDay pattern.

\(YearMonthDay y _ _) -> y

@mchav
Copy link
Author

mchav commented Dec 22, 2024

Yeah that's what I was referring to by tuple matching.

This might be too niche a request but figured it'd be good to ask anyway. I'm working on a dataframe library and I'm porting some datetime related examples from Python. For people starting out with Haskell and I suggest the approach you mention in the tutorial but I thought this might be the sort of thing that makes that would make the library easier to use so could be an upstream change.

So the above example would make sense to write as:

df & D.as "birth_year" D.apply "birthdate" gregorianYear

What do you think?

@mchav
Copy link
Author

mchav commented Dec 22, 2024

I also just realized your approach is different from the tuple approach. Sorry. Should have read that more closely. I guess that makes my concern less pressing but the gist of it still holds, I think.

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