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

Support tuple in by function #6

Open
TymonKilich opened this issue Jun 15, 2020 · 0 comments
Open

Support tuple in by function #6

TymonKilich opened this issue Jun 15, 2020 · 0 comments

Comments

@TymonKilich
Copy link

Sorting by multiple columns using usual (non-natural) sorting works:

sort([["a1",  "a2"], ["a10", "a5"], ["a7", "a11"], ["a1", "a11"]], by = cols -> (cols[1], cols[2]))

and returns (sorted but not naturally):

4-element Array{Array{String,1},1}:
 ["a1", "a11"]
 ["a1", "a2"]
 ["a10", "a5"]
 ["a7", "a11"]

However, the same doesn't work for lt=natural

julia> using NaturalSort
julia> sort([["a1",  "a2"], ["a10", "a5"], ["a7", "a11"], ["a1", "a11"]], by = cols -> (cols[1], cols[2]), lt=natural)
ERROR: MethodError: no method matching natural(::Tuple{String,String}, ::Tuple{String,String})
Stacktrace:
 [1] (::Base.Order.var"#1#2"{typeof(natural),var"#21#22"})(::Array{String,1}, ::Array{String,1}) at ./ordering.jl:70
 [2] lt(::Base.Order.Lt{Base.Order.var"#1#2"{typeof(natural),var"#21#22"}}, ::Array{String,1}, ::Array{String,1}) at ./ordering.jl:53
 [3] sort! at ./sort.jl:480 [inlined]
 [4] sort!(::Array{Array{String,1},1}, ::Int64, ::Int64, ::Base.Sort.MergeSortAlg, ::Base.Order.Lt{Base.Order.var"#1#2"{typeof(natural),var"#21#22"}}, ::Array{Array{String,1},1}) at ./sort.jl:565
 [5] sort! at ./sort.jl:564 [inlined]
 [6] sort! at ./sort.jl:655 [inlined]
 [7] #sort!#7 at ./sort.jl:715 [inlined]
 [8] #sort#8 at ./sort.jl:763 [inlined]
 [9] top-level scope at REPL[15]:1

though it works with single argument (non-tuple) by function:

julia> sort([["a1",  "a2"], ["a10", "a5"], ["a7", "a11"], ["a1", "a11"]], by = cols -> cols[2], lt=natural)
4-element Array{Array{String,1},1}:
 ["a1", "a2"]
 ["a10", "a5"]
 ["a7", "a11"]
 ["a1", "a11"]

julia> sort([["a1",  "a2"], ["a10", "a5"], ["a7", "a11"], ["a1", "a11"]], by = cols -> cols[1], lt=natural)
4-element Array{Array{String,1},1}:
 ["a1", "a2"]
 ["a1", "a11"]
 ["a7", "a11"]
 ["a10", "a5"]
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