diff --git a/Project.toml b/Project.toml index d99b22e..81f9310 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "DataAPI" uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" authors = ["quinnj "] -version = "1.13.0" +version = "1.14.0" [compat] julia = "1" diff --git a/src/DataAPI.jl b/src/DataAPI.jl index 8e13733..00af0d0 100644 --- a/src/DataAPI.jl +++ b/src/DataAPI.jl @@ -183,9 +183,9 @@ Between(x::Union{Int, Symbol}, y::AbstractString) = Between(x, Symbol(y)) Between(x::AbstractString, y::Union{Int, Symbol}) = Between(Symbol(x), y) """ - All(cols...) + All() -Select the union of the selections in `cols`. If `cols == ()`, select all columns. +Select all columns. """ struct All{T<:Tuple} cols::T @@ -198,17 +198,24 @@ struct All{T<:Tuple} end """ - Cols(cols...) - Cols(f::Function) + Cols(cols...; operator=union) + Cols(f::Function; operator=union) -Select the union of the selections in `cols`. If `cols == ()`, select no columns. +Select columns matching specifications in `cols`. If `cols == ()`, select no columns. If the only positional argument is a `Function` `f` then select the columns whose names passed to the `f` predicate as strings return `true`. + +When multiple `cols` selectors are passed then the sets of columns selected by them +are passed to `operator` as positional arguments. +`operator` should be a set operation function, like `union`, `intersect`, `setdiff`, and `symdiff` +defined in Base Julia. By default `operator=union` in which case all columns matching +at least one selector are returned. """ struct Cols{T<:Tuple} cols::T - Cols(args...) = new{typeof(args)}(args) + operator + Cols(args...; operator=union) = new{typeof(args)}(args, operator) end """ diff --git a/test/runtests.jl b/test/runtests.jl index 72f0691..00e56ed 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -249,6 +249,8 @@ end (Ref(DataAPI.BroadcastedSelector(v())) .=> [sum, float]) end + @test DataAPI.Cols(:a, operator=union).operator == union + @test DataAPI.Cols(:a, operator=intersect).operator == intersect end @testset "unwrap" begin