Coder Social home page Coder Social logo

curry.jl's Introduction

Curry

This package demonstrates the syntax variant of currying. For theoretical background and history: Currying.

Essentially it allows to define

    @curry f(x)(y)(z) = F(x,y,z)
    
meaning the same as

    f = (x) -> (y) -> (z) -> F(x,y,z)
and
    f(x) = (y) -> (z) -> F(x,y,z)

The argument lists may be tuples and contain ellipses ... after the final argument and keyword arguments.

usage

julia> using Curry

julia> @curry f(x)(y) = x + y
f (generic function with 1 method)

julia> f(42)
#1 (generic function with 1 method)

julia> f(42)(1)
43

julia> using Unicode

julia> @curry function g(trans::Function)(s::AbstractString...)
           trans.(s)
       end
g (generic function with 1 method)

julia> all_upper = g(uppercase)
#5 (generic function with 1 method)

julia> all_upper("abc", "dEf")
("ABC", "DEF")

The following example shows, how the parsed expression is transformed.

julia> :(f(x)(y,z) = nothing)
:((f(x))(y, z) = begin
          #= REPL[21]:1 =#
          nothing
      end)

julia> curry(:(f(x)(y,z) = nothing))
:($(Expr(:escape, :(f(x) = begin
          #= line 0 =#
          (y, z)->begin
                  #= REPL[22]:1 =#
                  nothing
              end
      end))))

The function ldump is also contained in the package and prints Expr objects in a list form.

julia> ldump(:(f(x)(y,z) = nothing))
(=
  (call
    (call
      Symbol f
      Symbol x
    )
    Symbol y
    Symbol z
  )
  (block
    Symbol nothing
  )
)

julia> ldump(curry(:(f(x)(y,z) = nothing)))
(escape
  (=
    (call
      Symbol f
      Symbol x
    )
    (block
      (->
        (tuple
          Symbol y
          Symbol z
        )
        (block
          Symbol nothing
        )
      )
    )
  )
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.