Giter Site home page Giter Site logo

fn.el's Introduction

fn.el -- Concise anonymous functions for Emacs Lisp.

fn.el provides macros for writing concise and readable anonymous functions.

MELPA MELPA Stable


Installation

  • Install from melpa using M-x list-packages.

  • Or, place fn.el in any directory on your load-path and execute:

    (require 'fn)


API

  • fn (&rest body)
  • fn: (&rest body)

fn (&rest BODY)

Return a function defined by BODY.

Intended for inline use where concision is desired. If creating a function to bind as a function value, use lambda or -lambda.

The definition BODY may use anaphoric parameters to refer to the arguments. For a single-argument function, <> can be used. For a multiple-argument function, use <1> to refer to the first argument, <2> to refer to the second, and so on up to <9>. The parameter <rest> refers to a list containing the (n+1)st and later arguments, where <n> is the highest numerical parameter supplied.

If applied to a literal, creates a constant function, or equivalently, a thunk (since it can be called with any number of arguments).

(-map (fn (* <> <>)) (number-sequence 0 10))
;; (0 1 4 9 16 25 36 49 64 81 100)

(-map (fn (/ (-sum <>)
            (length <>)))
      '((3.0 4.0 5.0 5.0 10.0)
        (1.5 2.5 2.0)
        (1 5)))
;; (5.4 2.0 3)
;; find average of each list

(-filter (fn (zerop (mod <> 3)))
        (number-sequence 1 10))
;; (3 6 9)

(funcall (fn 7))
;; 7

(funcall (fn (-map #'list <rest>)) 1 2 3 4)
;; ((1) (2) (3) (4))

fn: (&rest BODY)

Return a function defined by (BODY).

Intended for inline use where concision is desired. If creating a function to bind as a function value, use lambda or -lambda.

Identical to fn except that BODY is automatically parenthesized.

The definition BODY may use the anaphoric parameter <> for the sole argument, or <1> ... <9> to refer to multiple positional arguments. The parameter <rest> refers to a list containing the (n+1)st and later arguments, where <n> is the highest numerical parameter supplied.

(-map (fn: * <> <>) (number-sequence 0 10))
;; (0 1 4 9 16 25 36 49 64 81 100)

(-filter (fn: > <> 0)
        '(-5 2 0 0 3 -1 0 4))
;; (2 3 4)

fn.el's People

Contributors

basil-conto avatar troyp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fn.el's Issues

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.