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

Multiple updates #1

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Multiple updates #1

wants to merge 11 commits into from

Conversation

goretkin
Copy link
Contributor

If you'd prefer smaller PRs, I can break it up.

  • define map on FrankenTuples
  • ftcall works for anything that may support function calls, not just <:Function
  • update hasmethod to use code in Base that came out of this package to begin with!
  • use GitHub Actions for CI and building documentation
  • misc. other things

ftcall(f, ft::FrankenTuple{Tuple{},(),Tuple{}}) = f()

# NOTE: this method signature makes sure we don't define map(f)
function Base.map(f, ft::FrankenTuple, fts::FrankenTuple...)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this definition of map really jives with what map does for other collections, since iteration of FrankenTuples provides the elements in sequence rather than treating the named and unnamed parts separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I think that might be okay. I wonder if perhaps you expect isequal(map(f, c), map(f, collect(c))) (which I kind of expect as well). However that's already not the case for NamedTuple (second test below):

using FrankenTuples

function _test_map(f, c)
    (map(f, c), map(f, collect(c)))
end

@show _test_map(sqrt, (1, 4))
@show _test_map(sqrt, (a=9, b=16))
@show _test_map(sqrt, @ftuple (1, 4, a=9, b=16))
_test_map(sqrt, (1, 4)) = ((1.0, 2.0), [1.0, 2.0])
_test_map(sqrt, (a = 9, b = 16)) = ((a = 3.0, b = 4.0), [3.0, 4.0])
_test_map(sqrt,  @ftuple((1, 4, a = 9, b = 16))) = (FrankenTuple((1.0, 2.0), (a = 3.0, b = 4.0)), [1.0, 2.0, 3.0, 4.0])

I think the right "invariant" is

function test_map_collect_commute(f, c)
    isequal(
        collect(map(f, c)),
        map(f, collect(c))
    )
end

@show test_map_collect_commute(sqrt, (1, 4))
@show test_map_collect_commute(sqrt, (a=9, b=16))
@show test_map_collect_commute(sqrt, @ftuple (1, 4, a=9, b=16))

and it gives

test_map_collect_commute(sqrt, (1, 4)) = true
test_map_collect_commute(sqrt, (a = 9, b = 16)) = true
test_map_collect_commute(sqrt, @ftuple((1, 4, a = 9, b = 16))) = true

Copy link
Contributor Author

@goretkin goretkin Jul 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ararslan What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see that you've just recently cherry picked some of the commits from this PR, and addressed some of the other commits too. Great!

Is map the only thing that this PR would add, then?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, just wanted to get the repo into a better state then discuss/ruminate on map separately. I made sure to preserve your authorship for things you fixed!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed, and I appreciate it :)

@goretkin goretkin mentioned this pull request Jun 29, 2022
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