Skip to content

Commit

Permalink
Use opcompose (#16)
Browse files Browse the repository at this point in the history
Also update the minimum Transducers version to 0.4.39.
  • Loading branch information
tkf authored Jul 4, 2020
1 parent f2e7095 commit a18a297
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ BangBang = "0.3.24"
Compat = "2.2, 3"
InitialValues = "0.2.6"
OnlineStats = "1"
Transducers = "0.4.35"
Transducers = "0.4.39"
julia = "1"

[extras]
Expand Down
21 changes: 13 additions & 8 deletions src/LazyGroupBy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ _groupby_kwargs(; init = Transducers.DefaultInit, kwargs...) = ((init,), kwargs)
function _impl_fold(fold, kwargs, rf, xf, group)
(init,), kwargs = _groupby_kwargs(; kwargs...)
prexf, collection = extract_transducer(group.collection)
gxf = prexf |> GroupBy(group.key, Map(last) |> xf, rf, init)
gxf = opcompose(prexf, GroupBy(group.key, opcompose(Map(last), xf), rf, init))
d = fold(right, gxf, collection; init = nothing, kwargs...)
if d === nothing
error("input collection is empty or all filtered out")
Expand All @@ -115,23 +115,23 @@ impl(::typeof(dreduce), kwargs, rf, xs) = impl(dreduce, kwargs, rf, Map(identity

impl(::typeof(collect), kwargs, xf::Transducer, group::GroupedBy) = foldl(
right,
GroupBy(group.key, Map(last) |> xf |> Map(SingletonVector), append!!),
GroupBy(group.key, opcompose(Map(last), xf, Map(SingletonVector)), append!!),
group.collection,
)
impl(::typeof(collect), kwargs, group::GroupedBy) =
impl(collect, kwargs, IdentityTransducer(), group)

impl(::typeof(tcollect), kwargs, xf::Transducer, group::GroupedBy) = reduce(
right,
GroupBy(group.key, Map(last) |> xf |> Map(SingletonVector), append!!),
GroupBy(group.key, opcompose(Map(last), xf, Map(SingletonVector)), append!!),
group.collection,
)
impl(::typeof(tcollect), kwargs, group::GroupedBy) =
impl(tcollect, kwargs, IdentityTransducer(), group)

impl(::typeof(dcollect), kwargs, xf::Transducer, group::GroupedBy) = dreduce(
right,
GroupBy(group.key, Map(last) |> xf |> Map(SingletonVector), append!!),
GroupBy(group.key, opcompose(Map(last), xf, Map(SingletonVector)), append!!),
group.collection;
kwargs...,
)
Expand Down Expand Up @@ -223,7 +223,10 @@ impl(::typeof(findfirst), ::NamedTuple{()}, f, group::GroupedBy) = foldl(
right,
GroupBy(
group.key last,
Filter(((_key, (_idx, val)),) -> f(val)) |> Map(((_key, (idx, _val)),) -> idx),
opcompose(
Filter(((_key, (_idx, val)),) -> f(val)),
Map(((_key, (idx, _val)),) -> idx),
),
left,
),
pairs(group.collection),
Expand All @@ -235,7 +238,7 @@ impl(::typeof(findlast), ::NamedTuple{()}, f, group::GroupedBy) = foldl(
right,
GroupBy(
group.key last,
Filter(((_key, (_idx, val)),) -> f(val)) |> Map(((_key, (idx, _val)),) -> idx),
opcompose(Filter(((_key, (_idx, val)),) -> f(val)), Map(((_key, (idx, _val)),) -> idx)),
right,
),
pairs(group.collection),
Expand All @@ -245,8 +248,10 @@ impl(::typeof(findall), kwargs, f, group::GroupedBy) = foldl(
right,
GroupBy(
group.key last,
Filter(((_key, (_idx, val)),) -> f(val)) |>
Map(((_key, (idx, _val)),) -> SingletonVector(idx)),
opcompose(
Filter(((_key, (_idx, val)),) -> f(val)),
Map(((_key, (idx, _val)),) -> SingletonVector(idx)),
),
append!!,
),
pairs(group.collection),
Expand Down
11 changes: 8 additions & 3 deletions test/environments/main/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ git-tree-sha1 = "a6a8197ae253f2c1a22b2ae17c2dfaf5812c03aa"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "3.13.0"

[[CompositionsBase]]
git-tree-sha1 = "f3955eb38944e5dd0fabf8ca1e267d94941d34a5"
uuid = "a33af91c-f02d-484b-be07-31d278c5ca2b"
version = "0.1.0"

[[ConstructionBase]]
git-tree-sha1 = "a2a6a5fea4d6f730ec4c18a76d27ec10e8ec1c50"
uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
Expand Down Expand Up @@ -256,12 +261,12 @@ deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[Transducers]]
deps = ["ArgCheck", "BangBang", "Distributed", "InitialValues", "Logging", "Markdown", "Requires", "Setfield", "SplittablesBase", "Tables"]
git-tree-sha1 = "3ffdba968ea18a106c7084283d58ee022297c9ce"
deps = ["ArgCheck", "BangBang", "CompositionsBase", "Distributed", "InitialValues", "Logging", "Markdown", "Requires", "Setfield", "SplittablesBase", "Tables"]
git-tree-sha1 = "329e69f3104057ae0aaab823c447bd7d5aae1d8b"
repo-rev = "master"
repo-url = "https://github.com/JuliaFolds/Transducers.jl.git"
uuid = "28d57a85-8fef-5791-bfe6-a80928e7c999"
version = "0.4.37-DEV"
version = "0.4.39"

[[UUIDs]]
deps = ["Random", "SHA"]
Expand Down

0 comments on commit a18a297

Please sign in to comment.