All Projects → archermarx → PartialFunctions.jl

archermarx / PartialFunctions.jl

Licence: MIT license
A small package to simplify partial function application

Programming Languages

julia
2034 projects

Projects that are alternatives of or similar to PartialFunctions.jl

J-Curry
A Java library that enables applying Functional Programming concepts like currying and partial application for functions, also it supports types like Either, Try, etc... using RxJava 2 interfaces, compatible with Java 7 and above
Stars: ✭ 17 (-50%)
Mutual labels:  curry, currying, partial
morphmorph
😱 Isomorphic transformations. Map, transform, filter, and morph your objects
Stars: ✭ 26 (-23.53%)
Mutual labels:  functional, function-composition
invokable
Objects are functions! Treat any Object or Class as a Proc (like Enumerable but for Procs).
Stars: ✭ 40 (+17.65%)
Mutual labels:  curry, currying
iterum
Handling iterables like lazy arrays.
Stars: ✭ 28 (-17.65%)
Mutual labels:  functional, lazy-evaluation
ftor
ftor enables ML-like type-directed, functional programming with Javascript including reasonable debugging.
Stars: ✭ 44 (+29.41%)
Mutual labels:  currying, lazy-evaluation
fpEs
Functional Programming for EcmaScript(Javascript)
Stars: ✭ 40 (+17.65%)
Mutual labels:  curry, currying
vector
A PHP functional programming library.
Stars: ✭ 19 (-44.12%)
Mutual labels:  functional, currying
unpythonic
Supercharge your Python with parts of Lisp and Haskell.
Stars: ✭ 53 (+55.88%)
Mutual labels:  currying, lazy-evaluation
transmute
kind of like lodash but works with Immutable
Stars: ✭ 35 (+2.94%)
Mutual labels:  functional, curry
fnts
λ Minimal Functional Programming Utilities for TypeScript & JavaScript
Stars: ✭ 75 (+120.59%)
Mutual labels:  functional, function
lambda-zero
A minimalist pure lazy functional programming language
Stars: ✭ 65 (+91.18%)
Mutual labels:  functional, lazy-evaluation
dry-transformer
Data transformation toolkit
Stars: ✭ 59 (+73.53%)
Mutual labels:  functional, function-composition
Function2
Improved and configurable drop-in replacement to std::function that supports move only types, multiple overloads and more
Stars: ✭ 290 (+752.94%)
Mutual labels:  functional, function
hawkweed
Yet another implementation of missing functions for Python
Stars: ✭ 20 (-41.18%)
Mutual labels:  functional, currying
fn
Functional library for PHP with proper currying
Stars: ✭ 22 (-35.29%)
Mutual labels:  functional, curry
justuse
Just use() code from anywhere - a functional import alternative with advanced features like inline version checks, autoreload, module globals injection before import and more.
Stars: ✭ 49 (+44.12%)
Mutual labels:  functional
chip-8
A CHIP-8 Emulator written in Haskell
Stars: ✭ 34 (+0%)
Mutual labels:  functional
Functor
Mappable objects
Stars: ✭ 20 (-41.18%)
Mutual labels:  function
php-validation-dsl
A DSL for validating data in a functional fashion
Stars: ✭ 47 (+38.24%)
Mutual labels:  functional
dotvariant
A type-safe and space-efficient sum type for C# (comparable to discriminated unions in C or C++)
Stars: ✭ 52 (+52.94%)
Mutual labels:  functional

PartialFunctions

Stable Dev Build Status Coverage Status Downloads

This is a small Julia package that makes partial function application as simple as possible

Usage

To apply an argument x to a function f, use the $ binary operator like so

julia> f $ x
f(x, ...)

To apply multiple arguments, wrap them in a Tuple, like you would a normal function call

julia> f $ (x, y, z)
f(x, y, z, ...)
julia> f = println $ (("This is", "a Tuple"),)
println(("This is", "a Tuple"), ...)

julia> f(", and this is an additional argument")
("This is", "a Tuple"), and this is an additional argument

You can add keyword arguments by passing a NamedTuple

julia> sort_by_length = sort $ (;by = length)
sort(...; by = length, ...)

julia> sort_by_length([[1,2,3], [1,2]])
2-element Vector{Vector{Int64}}:
 [1, 2]
 [1, 2, 3]

You can pass arguments and keyword arguments at the same time

julia> a = [[1,2,3], [1,2]];

julia> sort_a_by_length = sort $ (a, (;by = length))
sort([[1, 2, 3], [1, 2]], ...; by = length, ...)

julia> sort_a_by_length()
2-element Vector{Vector{Int64}}:
 [1, 2]
 [1, 2, 3]

You can also pass a tuple of arguments to this form, or pass the args first then the keyword args second to reduce the number of parentheses. Care must be taken here to avoid unintended results.

# These are equivalent
sort $ a $ (;by = length)
sort $ (a, (;by = length))
sort $ ((a,), (;by = length))

# These are incorrect, or will yield unintended results
julia> sort $ (a, by = length)
sort(..., a = [[1,2,3], [1,2]], by = length) # a treated as part of NamedTuple

julia> sort $ (a; by = length)
sort(length, ... ) # the argument is an expression that evaluates to 'length'

Examples

julia> using PartialFunctions

julia> a(x) = x^2
a (generic function with 1 method)

julia> f = map $ a
map(a, ...)

julia> f([1,2,3])
3-element Array{Int64,1}:
 1
 4
 9
julia> simonsays = println $ "Simon says: "
println("Simon says: ", ...)

julia> simonsays("Partial function application is cool!")
Simon says: Partial function application is cool!

The Reverse Pipe

PartialFunctions also exports the <|, or "reverse pipe" operator, which can be used to apply the arguments succeeding it to the function preceding it. This operator has low precedence, making it useful when chaining function calls if one wants to avoid a lot of parentheses

Here's an extremely contrived example to add a bunch of numbers together

julia> (+) $ 2 $ 3 $ 5 $ 10 <| 12
32

Unlike the normal pipe (|>), it can also be used with tuples of arguments

julia> (+) <| (1, 2)...
3

Passing an empty tuple calls the preceding function with zero arguments

julia> a = isequal $ (1, 2)
isequal(1, 2, ...)

julia> isequal $ (1, 2) <| ()   # equivalent to a() or isequal(1, 2)
false
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].