# Method of \`open\` that applies a function to various files

**URL:** <https://discourse.julialang.org/t/method-of-open-that-applies-a-function-to-various-files/38732>\
**Category:** Package Announcements\
**Created:** [May 4, 2020, 10:52am UTC](https://discourse.julialang.org/t/method-of-open-that-applies-a-function-to-various-files/38732 "2020-05-04T10:52:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [May 4, 2020, 10:52am UTC](https://discourse.julialang.org/t/method-of-open-that-applies-a-function-to-various-files/38732/1 "2020-05-04T10:52:30Z")

</div>

I have made this very tiny package to help myself in a very common use case, when I want to read data from big files and write results of processing its contents into another, chunk by chunk.

> **[GitHub - heliosdrm/IOExtension.jl: Extension to Julia IO functions](https://github.com/heliosdrm/IOExtension.jl/)**
>
> Extension to Julia IO functions. Contribute to heliosdrm/IOExtension.jl development by creating an account on GitHub.

It only contains a new method for `Base.open`, which essentially mimicks `open(f::Function, args...; kwargs...)` from `base/io.jl`, but is specific for the case when the first item of `args` is a tuple that identifies various files. It opens all the files with the given options by broadcasting, and applys `f` --which should take as many arguments as files given–, closing the files upon completion.

As far as I know `open(::Function, ::Tuple{Vararg}, args...; kwargs...)` does not exist in `Base`, so this should not break anything.

Take it if you think it may be useful for you too. Improvements and extensions are welcome.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 4, 2020, 10:57am UTC](https://discourse.julialang.org/t/method-of-open-that-applies-a-function-to-various-files/38732/2 "2020-05-04T10:57:53Z")

</div>

> [@heliosdrm](#):
>
> As far as I know `open(::Function, ::Tuple{Vararg}, args...; kwargs...)` does not exist in `Base` , so this should not break anything.

Since your package does define neither the function nor the argument types, this is type piracy.

[https://docs.julialang.org/en/v1/manual/style-guide/#Avoid-type-piracy-1](https://docs.julialang.org/en/v1/manual/style-guide/#Avoid-type-piracy-1)

---

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [May 4, 2020, 11:13am UTC](https://discourse.julialang.org/t/method-of-open-that-applies-a-function-to-various-files/38732/3 "2020-05-04T11:13:04Z")

</div>

Thanks, I have added a note to warn about this in the README file.

What would be the preferred way to avoid type piracy in this case?

- Move this functionality to a function not from `Base` -e.g. `openmultiple`?
- Make a PR to Base instead of putting this in a separate package?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 4, 2020, 11:22am UTC](https://discourse.julialang.org/t/method-of-open-that-applies-a-function-to-various-files/38732/4 "2020-05-04T11:22:21Z")

</div>

A different name for the function would be the simplest solution IMO.

---

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [May 4, 2020, 11:26am UTC](https://discourse.julialang.org/t/method-of-open-that-applies-a-function-to-various-files/38732/5 "2020-05-04T11:26:43Z")

</div>

Good, I have changed it. Now this is made by a function called `openmultiple`.  
Thanks for the advice!

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [May 4, 2020, 11:30am UTC](https://discourse.julialang.org/t/method-of-open-that-applies-a-function-to-various-files/38732/6 "2020-05-04T11:30:28Z")

</div>

A third alternative is to just not overload `Base.open` and let people use

```julia
IOExtension.open(...)

```
