https://github.com/orbots/curry.jl
Currying for Julia
https://github.com/orbots/curry.jl
hacktoberfest
Last synced: 2 months ago
JSON representation
Currying for Julia
- Host: GitHub
- URL: https://github.com/orbots/curry.jl
- Owner: Orbots
- License: mit
- Created: 2019-03-30T00:35:01.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-09T17:20:10.000Z (about 1 year ago)
- Last Synced: 2024-04-14T07:12:37.621Z (about 1 year ago)
- Topics: hacktoberfest
- Language: Julia
- Homepage:
- Size: 24.4 KB
- Stars: 21
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Curry
Implementation of Currying for Julia. https://en.wikipedia.org/wiki/Currying
Convert a function that accepts multiple arguments into an equivalent chain of single argument functions.
Functions are chained as single argument anonymous functions that return single argument functions.If multiple arities of a function exist, the one with the least number of arguments greater than 1 will be curried.
e.g. arities 1 and greater than 2 exist for -, but arity 2 will be choosen for currying.Exports the following functions:
* `curry`
* `partial`
* `swap`Implements the following puns:
* `🍛` (exported)
* `∂`Examples:
# convert from 0-based array to 1-based. I use this all the time.
julia> 🍛(+)(1).([0,1,2,3]) |> show
[1, 2, 3, 4]julia> curry(map)(sqrt)(1:4)
4-element Array{Float64,1}:
1.0
1.4142135623730951
1.7320508075688772
2.0
julia> curry((-))(9)
#119 (generic function with 1 method)
julia> curry((-))(9)(1)
8julia> curry(reduce; init=10)(+)(1:5)
25