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

Add a function for materializing a container from its type #75

Merged
merged 2 commits into from
Nov 5, 2019
Merged
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
37 changes: 33 additions & 4 deletions benchmark/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"]
Expand Down
1 change: 1 addition & 0 deletions benchmark/Project.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
30 changes: 26 additions & 4 deletions docs/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"]
Expand Down
1 change: 1 addition & 0 deletions docs/src/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dtransduce
eduction
map!
copy!
copy
append!
Transducers.append!!
collect
Expand Down
2 changes: 1 addition & 1 deletion src/Transducers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions src/processes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
30 changes: 26 additions & 4 deletions test/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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"]
Expand Down