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

List methods don't work on Validity #246

Open
andrewbaxter opened this issue Mar 6, 2024 · 1 comment
Open

List methods don't work on Validity #246

andrewbaxter opened this issue Mar 6, 2024 · 1 comment

Comments

@andrewbaxter
Copy link

Right now list methods don't work with tuples (error about not being a list value) and there are no tuple-specific methods.

I think I saw it mentioned somewhere else, but there's no way to extract values from a tuple AFAICT. Validities are a special case where to_bool and to_int will extract the second and first values, but for user generated tuples there's no such option (and really, first and last or get(, 0) get(, 1) would probably be clearer for those anyway).

@andrewbaxter
Copy link
Author

andrewbaxter commented Mar 6, 2024

Sorry, I think I was somewhat confused here. first/last/get don't work on Validity data, despite being described as a tuple:

{:create hos {state: String, year: Validity => hos: String}}
{
?[state, year, hos] <- [['US', [2001, true], 'Bush'],
                        ['US', [2005, true], 'Bush'],
                        ['US', [2009, true], 'Obama'],
                        ['US', [2013, true], 'Obama'],
                        ['US', [2017, true], 'Trump'],
                        ['US', [2021, true], 'Biden']]

:put hos {state, year => hos}
}
{?[state, year] := *hos{state:state, year:year_}, year = first(year_)}

returns

  help: 'first' requires lists

They seem to work fine for user-generated tuples.

@andrewbaxter andrewbaxter changed the title Tuple methods List methods don't work on Validity Mar 6, 2024
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

1 participant