Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tk3369/functionalpipes.jl
Functional pipe utility
https://github.com/tk3369/functionalpipes.jl
functional-programming julia
Last synced: 1 day ago
JSON representation
Functional pipe utility
- Host: GitHub
- URL: https://github.com/tk3369/functionalpipes.jl
- Owner: tk3369
- License: mit
- Created: 2019-10-22T06:50:24.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-13T04:49:50.000Z (almost 4 years ago)
- Last Synced: 2024-07-30T18:34:41.268Z (4 months ago)
- Topics: functional-programming, julia
- Language: Julia
- Homepage:
- Size: 6.84 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FunctionalPipes
_Note: this package is experimental. Similar packages include Lazy.jl,
Hose.jl, and MagicUnderscores.jl._This package provides a simple facility to build functional pipes
that support functions taking more than a single argument. It also
allows the results from upstream be placed in any argument position.## Motivation
The pipe operator `|>` works well as long as the downstream
function takes a single argument. Otherwise, it becomes quite
awkward to make anonymous functions to work around the issue.
For example:```julia
[1,2,3] |> v -> filter(x -> x > 1, v) |> sum # 5
```## Features
Using the `pipe` function, we can build a computation pipe
as usual:```julia
pipe([1,2,3], sum, iseven) # true
```However, we can pass prior results to a function in any specific
argument position. The special token is 🔥 (or `:token`).```julia
pipe(
[1,2,3],
dispatch(filter, x -> x > 1, 🔥),
sum
)
```In fact, you can even have multiple tokens:
```julia
pipe(3, dispatch(+, 🔥, 🔥)) # 6
```If the dispatched function returns `nothing`, then it carries over
the prior result. This would be useful for functions that only
have side effects.```julia
julia> pipe(
1:10,
collect,
dispatch(filter, isodd, 🔥),
dispatch(println, "values: ", 🔥),
sum,
dispatch(println, "total: ", 🔥)
)
values: [1, 3, 5, 7, 9]
total: 25
25
```