diff --git a/Project.toml b/Project.toml index b7ff1dc7e6..ee166b39cb 100644 --- a/Project.toml +++ b/Project.toml @@ -15,7 +15,7 @@ Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46" [compat] ArgCheck = "1" -BangBang = "0.2, 0.3" +BangBang = "0.3.2" InitialValues = "0.2" Requires = "0.5" Setfield = "0.3, 0.4, 0.5" diff --git a/benchmark/Manifest.toml b/benchmark/Manifest.toml index 9c92e423f8..b39d0573f3 100644 --- a/benchmark/Manifest.toml +++ b/benchmark/Manifest.toml @@ -7,10 +7,12 @@ uuid = "dce04be8-c92d-5529-be00-80e4d2c0e197" version = "1.0.1" [[BangBang]] -deps = ["Future", "InitialValues", "LinearAlgebra", "Requires", "Setfield", "ZygoteRules"] -git-tree-sha1 = "6a721fca2a44ae40615712e6522ce1c12ac4726c" +deps = ["Compat", "ConstructionBase", "Future", "InitialValues", "LinearAlgebra", "Requires", "Tables", "ZygoteRules"] +git-tree-sha1 = "178ab91f57311b9375ade95bfefc8a8565263e89" +repo-rev = "master" +repo-url = "https://github.com/tkf/BangBang.jl.git" uuid = "198e06fe-97b7-11e9-32a5-e1d131e6ad66" -version = "0.3.1" +version = "0.3.2-DEV" [[Base64]] uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" @@ -38,12 +40,22 @@ git-tree-sha1 = "e3efe0a0f49dcd294c8c73e897b4fdf891f0fbd3" uuid = "187b0558-2788-49d3-abe0-74a17ed4e7c9" version = "0.1.0" +[[DataAPI]] +git-tree-sha1 = "674b67f344687a88310213ddfa8a2b3c76cc4252" +uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" +version = "1.1.0" + [[DataStructures]] deps = ["InteractiveUtils", "OrderedCollections"] git-tree-sha1 = "1fe8fad5fc84686dcbc674aa255bc867a64f8132" uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" version = "0.17.5" +[[DataValueInterfaces]] +git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6" +uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464" +version = "1.0.0" + [[Dates]] deps = ["Printf"] uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" @@ -69,6 +81,11 @@ version = "0.2.0" deps = ["Markdown"] uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" +[[IteratorInterfaceExtensions]] +git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856" +uuid = "82899510-4779-5014-852e-03e436cf321d" +version = "1.0.0" + [[JSON]] deps = ["Dates", "Mmap", "Parsers", "Unicode"] git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e" @@ -181,6 +198,18 @@ uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" deps = ["LinearAlgebra", "SparseArrays"] uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" +[[TableTraits]] +deps = ["IteratorInterfaceExtensions"] +git-tree-sha1 = "b1ad568ba658d8cbb3b892ed5380a6f3e781a81e" +uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" +version = "1.0.0" + +[[Tables]] +deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"] +git-tree-sha1 = "aaed7b3b00248ff6a794375ad6adf30f30ca5591" +uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" +version = "0.2.11" + [[Test]] deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" @@ -194,7 +223,7 @@ version = "0.5.6" deps = ["ArgCheck", "BangBang", "Distributed", "InitialValues", "Logging", "Markdown", "Requires", "Setfield"] path = ".." uuid = "28d57a85-8fef-5791-bfe6-a80928e7c999" -version = "0.4.3-DEV" +version = "0.4.4-DEV" [[UUIDs]] deps = ["Random", "SHA"] diff --git a/benchmark/Project.toml b/benchmark/Project.toml index c0003eee34..b1efea4380 100644 --- a/benchmark/Project.toml +++ b/benchmark/Project.toml @@ -1,5 +1,6 @@ [deps] ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197" +BangBang = "198e06fe-97b7-11e9-32a5-e1d131e6ad66" BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" diff --git a/docs/Manifest.toml b/docs/Manifest.toml index d0d6a9ef54..cc78632b80 100644 --- a/docs/Manifest.toml +++ b/docs/Manifest.toml @@ -7,10 +7,10 @@ uuid = "dce04be8-c92d-5529-be00-80e4d2c0e197" version = "1.0.1" [[BangBang]] -deps = ["ConstructionBase", "Future", "InitialValues", "LinearAlgebra", "Requires", "ZygoteRules"] -git-tree-sha1 = "3a1f4990976144727192fad89a9e3ead0733cae5" +deps = ["Compat", "ConstructionBase", "Future", "InitialValues", "LinearAlgebra", "Requires", "Tables", "ZygoteRules"] +git-tree-sha1 = "178ab91f57311b9375ade95bfefc8a8565263e89" repo-rev = "master" -repo-url = "https://github.com/tkf/BangBang.jl" +repo-url = "https://github.com/tkf/BangBang.jl.git" uuid = "198e06fe-97b7-11e9-32a5-e1d131e6ad66" version = "0.3.2-DEV" @@ -45,6 +45,11 @@ git-tree-sha1 = "1fe8fad5fc84686dcbc674aa255bc867a64f8132" uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" version = "0.17.5" +[[DataValueInterfaces]] +git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6" +uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464" +version = "1.0.0" + [[Dates]] deps = ["Printf"] uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" @@ -84,6 +89,11 @@ version = "0.2.0" deps = ["Markdown"] uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" +[[IteratorInterfaceExtensions]] +git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856" +uuid = "82899510-4779-5014-852e-03e436cf321d" +version = "1.0.0" + [[JSON]] deps = ["Dates", "Mmap", "Parsers", "Unicode"] git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e" @@ -248,6 +258,18 @@ git-tree-sha1 = "20da2784e79fc0bfdd70592d1b47d7a6034e82d1" uuid = "7522ee7d-7047-56d0-94d9-4bc626e7058d" version = "0.3.0" +[[TableTraits]] +deps = ["IteratorInterfaceExtensions"] +git-tree-sha1 = "b1ad568ba658d8cbb3b892ed5380a6f3e781a81e" +uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" +version = "1.0.0" + +[[Tables]] +deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"] +git-tree-sha1 = "aaed7b3b00248ff6a794375ad6adf30f30ca5591" +uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" +version = "0.2.11" + [[Test]] deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" @@ -261,7 +283,7 @@ version = "0.5.6" deps = ["ArgCheck", "BangBang", "Distributed", "InitialValues", "Logging", "Markdown", "Requires", "Setfield"] path = ".." uuid = "28d57a85-8fef-5791-bfe6-a80928e7c999" -version = "0.4.3-DEV" +version = "0.4.4-DEV" [[UUIDs]] deps = ["Random", "SHA"] diff --git a/docs/src/manual.md b/docs/src/manual.md index 6a992795df..f62ad26531 100644 --- a/docs/src/manual.md +++ b/docs/src/manual.md @@ -19,6 +19,7 @@ dtransduce eduction map! copy! +copy append! Transducers.append!! collect diff --git a/src/Transducers.jl b/src/Transducers.jl index f5d24e0b6b..d5e6af172f 100644 --- a/src/Transducers.jl +++ b/src/Transducers.jl @@ -14,7 +14,7 @@ export Distinct using Base.Broadcast: Broadcasted using ArgCheck -using BangBang: BangBang, append!!, empty!!, push!!, setindex!! +using BangBang: BangBang, Empty, append!!, empty!!, push!!, setindex!! using Distributed: Distributed, @everywhere using Logging: LogLevel, @logmsg using Requires diff --git a/src/processes.jl b/src/processes.jl index 1a112992f6..7f57cb2c46 100644 --- a/src/processes.jl +++ b/src/processes.jl @@ -590,6 +590,26 @@ function Base.collect(xf::Transducer, coll) end # Base.collect(xf, coll) = append!([], xf, coll) +""" + copy(xf::Transducer, T, foldable) :: Union{T, Nothing} + copy(xf::Transducer, foldable::T) :: Union{T, Nothing} + +Process `foldable` with a transducer `xf` and then create a container of type `T` +filled with the result. Return `nothing` if the transducer does not produce +anything. (This is because there is no consistent interface to create an empty +container given its type and not all containers support creating an empty +container.) +""" +function Base.copy(xf::Transducer, ::Type{T}, foldable) where T + result = append!!(Empty(T), foldable) + if result isa Empty + return nothing + end + return result +end + +Base.copy(xf::Transducer, foldable::T) where T = copy(xf, T, foldable) + """ map!(xf::Transducer, dest, src; simd) diff --git a/test/Manifest.toml b/test/Manifest.toml index f3c757b20b..b1d889073e 100644 --- a/test/Manifest.toml +++ b/test/Manifest.toml @@ -7,10 +7,10 @@ uuid = "dce04be8-c92d-5529-be00-80e4d2c0e197" version = "1.0.1" [[BangBang]] -deps = ["ConstructionBase", "Future", "InitialValues", "LinearAlgebra", "Requires", "ZygoteRules"] -git-tree-sha1 = "3a1f4990976144727192fad89a9e3ead0733cae5" +deps = ["Compat", "ConstructionBase", "Future", "InitialValues", "LinearAlgebra", "Requires", "Tables", "ZygoteRules"] +git-tree-sha1 = "178ab91f57311b9375ade95bfefc8a8565263e89" repo-rev = "master" -repo-url = "https://github.com/tkf/BangBang.jl" +repo-url = "https://github.com/tkf/BangBang.jl.git" uuid = "198e06fe-97b7-11e9-32a5-e1d131e6ad66" version = "0.3.2-DEV" @@ -51,6 +51,11 @@ git-tree-sha1 = "1fe8fad5fc84686dcbc674aa255bc867a64f8132" uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" version = "0.17.5" +[[DataValueInterfaces]] +git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6" +uuid = "e2d170a0-9d28-54be-80f0-106bbe20a464" +version = "1.0.0" + [[Dates]] deps = ["Printf"] uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" @@ -98,6 +103,11 @@ version = "0.2.0" deps = ["Markdown"] uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" +[[IteratorInterfaceExtensions]] +git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856" +uuid = "82899510-4779-5014-852e-03e436cf321d" +version = "1.0.0" + [[JSON]] deps = ["Dates", "Mmap", "Parsers", "Unicode"] git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e" @@ -268,6 +278,18 @@ git-tree-sha1 = "20da2784e79fc0bfdd70592d1b47d7a6034e82d1" uuid = "7522ee7d-7047-56d0-94d9-4bc626e7058d" version = "0.3.0" +[[TableTraits]] +deps = ["IteratorInterfaceExtensions"] +git-tree-sha1 = "b1ad568ba658d8cbb3b892ed5380a6f3e781a81e" +uuid = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c" +version = "1.0.0" + +[[Tables]] +deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"] +git-tree-sha1 = "aaed7b3b00248ff6a794375ad6adf30f30ca5591" +uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" +version = "0.2.11" + [[Test]] deps = ["Distributed", "InteractiveUtils", "Logging", "Random"] uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" @@ -281,7 +303,7 @@ version = "0.5.6" deps = ["ArgCheck", "BangBang", "Distributed", "InitialValues", "Logging", "Markdown", "Requires", "Setfield"] path = ".." uuid = "28d57a85-8fef-5791-bfe6-a80928e7c999" -version = "0.4.3-DEV" +version = "0.4.4-DEV" [[UUIDs]] deps = ["Random", "SHA"]