Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using Documenter, QueryOperators

makedocs(
modules = [QueryOperators],
sitename = "QueryOperators.jl",
modules=[QueryOperators],
sitename="QueryOperators.jl",
analytics="UA-132838790-1",
pages = [
pages=[
"Introduction" => "index.md"
]
)

deploydocs(
repo = "github.com/queryverse/QueryOperators.jl.git"
repo="github.com/queryverse/QueryOperators.jl.git"
)
22 changes: 11 additions & 11 deletions src/NamedTupleUtilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ julia> QueryOperators.NamedTupleUtilities.select((a=1,b=2,c=3),Val(:a))
(a = 1,)
```
"""
@generated function select(a::NamedTuple{an}, ::Val{bn}) where {an, bn}
@generated function select(a::NamedTuple{an}, ::Val{bn}) where {an,bn}
names = ((i for i in an if i == bn)...,)
types = Tuple{(fieldtype(a, n) for n in names)...}
vals = Expr[:(getfield(a, $(QuoteNode(n)))) for n in names]
Expand All @@ -23,7 +23,7 @@ julia> QueryOperators.NamedTupleUtilities.remove((a=1,b=2,c=3),Val(:c))
(a = 1, b = 2)
```
"""
@generated function remove(a::NamedTuple{an}, ::Val{bn}) where {an, bn}
@generated function remove(a::NamedTuple{an}, ::Val{bn}) where {an,bn}
names = ((i for i in an if i != bn)...,)
types = Tuple{(fieldtype(a, n) for n in names)...}
vals = Expr[:(getfield(a, $(QuoteNode(n)))) for n in names]
Expand All @@ -40,7 +40,7 @@ julia> QueryOperators.NamedTupleUtilities.range((a=1,b=2,c=3),Val(:a),Val(:b))
(a = 1, b = 2)
```
"""
@generated function range(a::NamedTuple{an}, ::Val{bn}, ::Val{cn}) where {an, bn, cn}
@generated function range(a::NamedTuple{an}, ::Val{bn}, ::Val{cn}) where {an,bn,cn}
rangeStarted = false
names = Symbol[]
for n in an
Expand Down Expand Up @@ -74,7 +74,7 @@ julia> QueryOperators.NamedTupleUtilities.rename((a = 1, b = 2, c = 3),Val(:a),V
ERROR: duplicate field name in NamedTuple: "c" is not unique
```
"""
@generated function rename(a::NamedTuple{an}, ::Val{bn}, ::Val{cn}) where {an, bn, cn}
@generated function rename(a::NamedTuple{an}, ::Val{bn}, ::Val{cn}) where {an,bn,cn}
names = Symbol[]
typesArray = DataType[]
vals = Expr[]
Expand All @@ -99,7 +99,7 @@ julia> QueryOperators.NamedTupleUtilities.startswith((abc=1,bcd=2,cde=3),Val(:a)
(abc = 1,)
```
"""
@generated function startswith(a::NamedTuple{an}, ::Val{bn}) where {an, bn}
@generated function startswith(a::NamedTuple{an}, ::Val{bn}) where {an,bn}
names = ((i for i in an if Base.startswith(String(i), String(bn)))...,)
types = Tuple{(fieldtype(a, n) for n in names)...}
vals = Expr[:(getfield(a, $(QuoteNode(n)))) for n in names]
Expand All @@ -114,7 +114,7 @@ julia> QueryOperators.NamedTupleUtilities.not_startswith((abc=1,bcd=2,cde=3),Val
(bcd = 2, cde = 3)
```
"""
@generated function not_startswith(a::NamedTuple{an}, ::Val{bn}) where {an, bn}
@generated function not_startswith(a::NamedTuple{an}, ::Val{bn}) where {an,bn}
names = ((i for i in an if !Base.startswith(String(i), String(bn)))...,)
types = Tuple{(fieldtype(a, n) for n in names)...}
vals = Expr[:(getfield(a, $(QuoteNode(n)))) for n in names]
Expand All @@ -129,7 +129,7 @@ julia> QueryOperators.NamedTupleUtilities.not_endswith((abc=1,bcd=2,cde=3),Val(:
(abc = 1, cde = 3)
```
"""
@generated function endswith(a::NamedTuple{an}, ::Val{bn}) where {an, bn}
@generated function endswith(a::NamedTuple{an}, ::Val{bn}) where {an,bn}
names = ((i for i in an if Base.endswith(String(i), String(bn)))...,)
types = Tuple{(fieldtype(a, n) for n in names)...}
vals = Expr[:(getfield(a, $(QuoteNode(n)))) for n in names]
Expand All @@ -144,7 +144,7 @@ julia> QueryOperators.NamedTupleUtilities.endswith((abc=1,bcd=2,cde=3),Val(:d))
(bcd = 2,)
```
"""
@generated function not_endswith(a::NamedTuple{an}, ::Val{bn}) where {an, bn}
@generated function not_endswith(a::NamedTuple{an}, ::Val{bn}) where {an,bn}
names = ((i for i in an if !Base.endswith(String(i), String(bn)))...,)
types = Tuple{(fieldtype(a, n) for n in names)...}
vals = Expr[:(getfield(a, $(QuoteNode(n)))) for n in names]
Expand All @@ -159,7 +159,7 @@ julia> QueryOperators.NamedTupleUtilities.occursin((abc=1,bcd=2,cde=3),Val(:d))
(bcd = 2, cde = 3)
```
"""
@generated function occursin(a::NamedTuple{an}, ::Val{bn}) where {an, bn}
@generated function occursin(a::NamedTuple{an}, ::Val{bn}) where {an,bn}
names = ((i for i in an if Base.occursin(String(bn), String(i)))...,)
types = Tuple{(fieldtype(a, n) for n in names)...}
vals = Expr[:(getfield(a, $(QuoteNode(n)))) for n in names]
Expand All @@ -174,7 +174,7 @@ julia> QueryOperators.NamedTupleUtilities.not_occursin((abc=1,bcd=2,cde=3),Val(:
(abc = 1,)
```
"""
@generated function not_occursin(a::NamedTuple{an}, ::Val{bn}) where {an, bn}
@generated function not_occursin(a::NamedTuple{an}, ::Val{bn}) where {an,bn}
names = ((i for i in an if !Base.occursin(String(bn), String(i)))...,)
types = Tuple{(fieldtype(a, n) for n in names)...}
vals = Expr[:(getfield(a, $(QuoteNode(n)))) for n in names]
Expand All @@ -193,7 +193,7 @@ julia> QueryOperators.NamedTupleUtilities.oftype((a = [4,5,6], b = [3.,2.,1.], c
NamedTuple()
```
"""
@generated function oftype(a::NamedTuple{an}, ::Val{b}) where {an, b}
@generated function oftype(a::NamedTuple{an}, ::Val{b}) where {an,b}
names = ((i for i in an if fieldtype(a, i) <: b)...,)
types = Tuple{(fieldtype(a, n) for n in names)...}
vals = Expr[:(getfield(a, $(QuoteNode(n)))) for n in names]
Expand Down
2 changes: 1 addition & 1 deletion src/enumerable/enumerable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ abstract type Enumerable end
Base.IteratorSize(::Type{T}) where {T <: Enumerable} = Base.SizeUnknown()
IteratorInterfaceExtensions.isiterable(x::Enumerable) = true

haslength(S) = Base.IteratorSize(S) isa Union{Base.HasLength, Base.HasShape} ? Base.HasLength() : Base.IteratorSize(S)
haslength(S) = Base.IteratorSize(S) isa Union{Base.HasLength,Base.HasShape} ? Base.HasLength() : Base.IteratorSize(S)
2 changes: 1 addition & 1 deletion src/enumerable/enumerable_count.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ function count(source::Enumerable, filter::Function, filter_expr::Expr)
end

function count(source::Enumerable)
return Base.count(i->true, source)
return Base.count(i -> true, source)
end
16 changes: 8 additions & 8 deletions src/enumerable/enumerable_defaultifempty.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Base.eltype(iter::Type{EnumerableDefaultIfEmpty{T,S}}) where {T,S} = T

_default_value_expr(::Type{T}) where {T} = :( DataValues.DataValue{$T}() )

_default_value_expr(::Type{T}) where {T<:DataValues.DataValue} = :( $T() )
_default_value_expr(::Type{T}) where {T <: DataValues.DataValue} = :( $T() )

function _default_value_expr(::Type{T}) where {T<:NamedTuple}
return :( NamedTuple{$(fieldnames(T))}( ($( (_default_value_expr(fieldtype(T,i)) for i in 1:length(fieldnames(T)))... ),)) )
function _default_value_expr(::Type{T}) where {T <: NamedTuple}
return :( NamedTuple{$(fieldnames(T))}(($( (_default_value_expr(fieldtype(T, i)) for i in 1:length(fieldnames(T)))... ),)) )
end

@generated function default_if_empty(source::S) where {S}
Expand All @@ -32,7 +32,7 @@ end

function default_if_empty(source::S, default_value::TD) where {S,TD}
T = eltype(source)
if T!=TD
if T != TD
error("The default value must have the same type as the elements from the source.")
end
return EnumerableDefaultIfEmpty{T,S}(source, default_value)
Expand All @@ -41,18 +41,18 @@ end
function Base.iterate(iter::EnumerableDefaultIfEmpty{T,S}) where {T,S}
s = iterate(iter.source)

if s===nothing
if s === nothing
return iter.default_value, nothing
else
return convert(T,s[1]), s[2]
return convert(T, s[1]), s[2]
end
end

function Base.iterate(iter::EnumerableDefaultIfEmpty{T,S}, state) where {T,S}
state===nothing && return nothing
state === nothing && return nothing

s = iterate(iter.source, state)
if s===nothing
if s === nothing
return nothing
else
return convert(T, s[1]), s[2]
Expand Down
4 changes: 2 additions & 2 deletions src/enumerable/enumerable_drop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ Base.IteratorSize(::Type{EnumerableDrop{T,S}}) where {T,S} = (Base.IteratorSize(

Base.eltype(::Type{EnumerableDrop{T,S}}) where {T,S} = T

Base.length(iter::EnumerableDrop{T,S}) where {T,S} = max(length(iter.source)-iter.n,0)
Base.length(iter::EnumerableDrop{T,S}) where {T,S} = max(length(iter.source) - iter.n, 0)

function Base.iterate(iter::EnumerableDrop{T,S}) where {T,S}
ret = iterate(iter.source)
for i in 1:iter.n
if ret===nothing
if ret === nothing
return nothing
else
ret = iterate(iter.source, ret[2])
Expand Down
4 changes: 2 additions & 2 deletions src/enumerable/enumerable_filter.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# T is the type of the elements produced by this iterator
struct EnumerableFilter{T,S,Q<:Function} <: Enumerable
struct EnumerableFilter{T,S,Q <: Function} <: Enumerable
source::S
filter::Q
end
Expand All @@ -16,7 +16,7 @@ end
function Base.iterate(iter::EnumerableFilter{T,S,Q}, state...) where {T,S,Q}
ret = iterate(iter.source, state...)

while ret!==nothing
while ret !== nothing
if iter.filter(ret[1])
return ret
end
Expand Down
20 changes: 10 additions & 10 deletions src/enumerable/enumerable_gather.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct Not{T}
val::T
end

function gather(source::Enumerable, args...; key::Symbol = :key, value::Symbol = :value)
function gather(source::Enumerable, args...; key::Symbol=:key, value::Symbol=:value)
fields = fieldnames(eltype(source))
if length(args) > 0
indexFields_vector = Vector{Symbol}(undef, 0)
Expand Down Expand Up @@ -39,24 +39,24 @@ function gather(source::Enumerable, args...; key::Symbol = :key, value::Symbol =
valueTypes = (fieldtype(eltype(source), indexField) for indexField in indexFields)
valueType = reduce(promote_type, valueTypes)

T = NamedTuple{(savedFields..., key, value), Tuple{savedFieldsType..., Symbol, valueType}}
return EnumerableGather{T, typeof(source), typeof(fields), typeof(indexFields), typeof(savedFields)}(source,
T = NamedTuple{(savedFields..., key, value),Tuple{savedFieldsType...,Symbol,valueType}}
return EnumerableGather{T,typeof(source),typeof(fields),typeof(indexFields),typeof(savedFields)}(source,
fields, indexFields, savedFields, key, value)
end

function Base.iterate(iter::EnumerableGather{T, S, F, I, A}) where {T, S, F, I, A}
function Base.iterate(iter::EnumerableGather{T,S,F,I,A}) where {T,S,F,I,A}
source_iterate = iterate(iter.source)
if source_iterate == nothing || length(iter.indexFields) == 0
return nothing
end
key = iter.indexFields[1]
current_source_row = source_iterate[1]
value = current_source_row[key]
return (T((Base.map(n->current_source_row[n], iter.savedFields)..., key, value)),
(current_source_row=current_source_row, source_state=source_iterate[2], current_index_field_index=1))
return (T((Base.map(n -> current_source_row[n], iter.savedFields)..., key, value)),
(current_source_row = current_source_row, source_state = source_iterate[2], current_index_field_index = 1))
end

function Base.iterate(iter::EnumerableGather{T, S, F, I, A}, state) where {T, S, F, I, A}
function Base.iterate(iter::EnumerableGather{T,S,F,I,A}, state) where {T,S,F,I,A}
current_index_field_index = state.current_index_field_index + 1
if current_index_field_index > length(iter.indexFields)
source_iterate = iterate(iter.source, state.source_state)
Expand All @@ -72,10 +72,10 @@ function Base.iterate(iter::EnumerableGather{T, S, F, I, A}, state) where {T, S,
end
key = iter.indexFields[current_index_field_index]
value = current_source_row[key]
return (T((Base.map(n->current_source_row[n], iter.savedFields)..., key, value)),
(current_source_row=current_source_row, source_state=source_state, current_index_field_index=current_index_field_index))
return (T((Base.map(n -> current_source_row[n], iter.savedFields)..., key, value)),
(current_source_row = current_source_row, source_state = source_state, current_index_field_index = current_index_field_index))
end

function Base.eltype(iter::EnumerableGather{T, S, F, I, A}) where {T, S, F, I, A}
function Base.eltype(iter::EnumerableGather{T,S,F,I,A}) where {T,S,F,I,A}
return T
end
34 changes: 17 additions & 17 deletions src/enumerable/enumerable_groupby.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
struct EnumerableGroupBySimple{T,TKey,TS,SO,ES<:Function} <: Enumerable
struct EnumerableGroupBySimple{T,TKey,TS,SO,ES <: Function} <: Enumerable
source::SO
elementSelector::ES
end
Expand All @@ -19,14 +19,14 @@ function Base.size(gcav::GroupColumnArrayView)
end

function Base.getindex(gcav::GroupColumnArrayView{T,G,INDEX}, i::Int) where {T,G,INDEX}
return getproperty(gcav.grouping[i],INDEX)
return getproperty(gcav.grouping[i], INDEX)
end

Base.IndexStyle(::Type{GroupColumnArrayView}) = IndexLinear()

function Base.getproperty(g::Grouping{TKey,T}, name::Symbol) where {TKey,T}

return GroupColumnArrayView{fieldtype(T,name),Grouping{TKey,T},name}(g)
return GroupColumnArrayView{fieldtype(T, name),Grouping{TKey,T},name}(g)
end

Base.size(A::Grouping{TKey,T}) where {TKey,T} = size(getfield(A, :elements))
Expand All @@ -45,42 +45,42 @@ function groupby(source::Enumerable, f_elementSelector::Function, elementSelecto

ES = typeof(f_elementSelector)

return EnumerableGroupBySimple{T,TKey,TS,SO,ES}(source,f_elementSelector)
return EnumerableGroupBySimple{T,TKey,TS,SO,ES}(source, f_elementSelector)
end

function Base.iterate(iter::EnumerableGroupBySimple{T,TKey,TS,SO,ES}) where {T,TKey,TS,SO,ES}
result = OrderedDict{TKey,T}()
for i in iter.source
key = iter.elementSelector(i)
if !haskey(result, key)
result[key] = T(key,Array{TS}(undef, 0))
result[key] = T(key, Array{TS}(undef, 0))
end
push!(getfield(result[key], :elements),i)
push!(getfield(result[key], :elements), i)
end

groups = collect(values(result))
if length(groups)==0
if length(groups) == 0
return nothing
else
return groups[1], (groups, 2)
end
end

function Base.iterate(iter::EnumerableGroupBySimple{T,TKey,TS,SO,ES}, state) where {T,TKey,TS,SO,ES}
if state[2]>length(state[1])
if state[2] > length(state[1])
return nothing
else
return state[1][state[2]], (state[1], state[2]+1)
return state[1][state[2]], (state[1], state[2] + 1)
end
end

struct EnumerableGroupBy{T,TKey,TR,SO,ES<:Function,RS<:Function} <: Enumerable
struct EnumerableGroupBy{T,TKey,TR,SO,ES <: Function,RS <: Function} <: Enumerable
source::SO
elementSelector::ES
resultSelector::RS
end

Base.eltype(::Type{EnumerableGroupBy{T,TKey,TR,SO,ES, RS}}) where {T,TKey,TR,SO,ES,RS} = T
Base.eltype(::Type{EnumerableGroupBy{T,TKey,TR,SO,ES,RS}}) where {T,TKey,TR,SO,ES,RS} = T

function groupby(source::Enumerable, f_elementSelector::Function, elementSelector::Expr, f_resultSelector::Function, resultSelector::Expr)
TS = eltype(source)
Expand All @@ -95,31 +95,31 @@ function groupby(source::Enumerable, f_elementSelector::Function, elementSelecto
ES = typeof(f_elementSelector)
RS = typeof(f_resultSelector)

return EnumerableGroupBy{T,TKey,TR,SO,ES,RS}(source,f_elementSelector,f_resultSelector)
return EnumerableGroupBy{T,TKey,TR,SO,ES,RS}(source, f_elementSelector, f_resultSelector)
end

function Base.iterate(iter::EnumerableGroupBy{T,TKey,TR,SO,ES}) where {T,TKey,TR,SO,ES}
result = OrderedDict{TKey,T}()
for i in iter.source
key = iter.elementSelector(i)
if !haskey(result, key)
result[key] = T(key,Array{TR}(undef,0))
result[key] = T(key, Array{TR}(undef, 0))
end
push!(getfield(result[key], :elements),iter.resultSelector(i))
push!(getfield(result[key], :elements), iter.resultSelector(i))
end

groups = collect(values(result))
if length(groups)==0
if length(groups) == 0
return nothing
else
return groups[1], (groups, 2)
end
end

function Base.iterate(iter::EnumerableGroupBy{T,TKey,TR,SO,ES}, state) where {T,TKey,TR,SO,ES}
if state[2]>length(state[1])
if state[2] > length(state[1])
return nothing
else
return state[1][state[2]], (state[1], state[2]+1)
return state[1][state[2]], (state[1], state[2] + 1)
end
end
Loading