https://github.com/qile0317/chainable.jl
Simplified function chaining in Julia.
https://github.com/qile0317/chainable.jl
julia julia-package macro
Last synced: 7 days ago
JSON representation
Simplified function chaining in Julia.
- Host: GitHub
- URL: https://github.com/qile0317/chainable.jl
- Owner: Qile0317
- License: mit
- Created: 2024-12-30T10:50:19.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-12-31T08:37:29.000Z (5 months ago)
- Last Synced: 2025-03-31T22:41:31.885Z (about 2 months ago)
- Topics: julia, julia-package, macro
- Language: Julia
- Homepage: https://qile0317.github.io/Chainable.jl/
- Size: 213 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Chainable.jl
[](https://github.com/Qile0317/Chainable.jl/actions/workflows/CI.yml?query=branch%3Amain)
[](https://app.codecov.io/gh/Qile0317/Chainable.jl?branch=main)
[](https://qile0317.github.io/Chainable.jl)
[](https://github.com/Qile0317/Chainable.jl/releases/latest)
[](https://github.com/Qile0317/Chainable.jl/LICENSE)Exports the `@chainable` macro to make any Julia function pipeline-friendly. `@chainable` Defines a new method for the function that takes the first argument as the data and the rest as parameters. The chainable function definition is directly done in the namespace so there are potential issues with namespace pollution, need for documentation, linter/static analysis errors, and memory overhead.
This macro almost certainly should ***not*** be used in a package or large project. However, for quick & simple research scripts it can be a useful utility to quickly produce clean code.
## Installation
```julia
using Pkg
Pkg.add(PackageSpec(name="Chainable", url = "https://github.com/Qile0317/Chainable.jl.git"))
```## Usage
```julia
using Chainable@chainable function transform(data, factor, offset)
return (data * factor) .+ offset
end# Use it in pipelines
1 |> transform(2, 3) # Same as: transform(1, 2, 3)# Chain multiple operations
[1, 2, 3] |>
transform(2, 0) |> # multiply by 2
transform(1, 1) # add 1# if default positional args are used, a named version must be used for piping
@chainable increment(x, inc = 1) = x + inc
1 |> increment() # works
1 |> increment(2) # this is undefined behaviour and will fail here.
1 |> increment(inc = 2) # works
# note that if increment(; inc = 1) is defined, then this will override the existing definition.
```At the moment, only positional arguments are supported. Function return type annotation is not supported.
## Roadmap
- [x] setup gh actions
- [ ] Add support for function return type annotation
- [x] Add support for default arguments (especially when there is argument type ambiguity in cases such as `@chainable LeakyRelu(x, a = 0.01) = max.(x * a, x`)
- [ ] Handle potential method overriding
- [ ] Add support for named arguments
- [ ] Add support for args and kwargs.
- [ ] Add support for broadcasting with `.`
- [ ] docsite
- [ ] register## Contributing
Any contributions and suggestions are welcome.