Socket
Socket
Sign inDemoInstall

lambdex

Package Overview
Dependencies
0
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    lambdex

A shorter lambda syntax for ES6


Version published
Maintainers
1
Created

Readme

Source

Lambdex is a JavaScript microlibrary which provides a syntax for describing anonymous functions which can be more compact than arrow notation, using the power of ES6 tagged template literals.

Here's one way to sum up the squares of all the numbers in an array using an ES6 arrow function:

[1,2,3,4].reduce((x, y) => x + y) // evaluates to 10

Using Lambdex, you could write this as:

import λ from 'lambdex'

[1,2,3,4].reduce`#0 + #1`)

Instead of defining a function by declaring names for all of its parameters and then showing how they are used in the functional expression, you just refer to the arguments by their index in the argument list. The lambdex expression #0 + #1 therefore means "a function of 2 parameters, which adds the first argument to the second".

A lambdex expression doesn't close over the variables in its scope, but you can insert values from the outside world into a lambdex expression using ${...} notation. For example,

const field = 'x'
[{x: 8}, {x: 3}, {x: 9}].map`#0[${field}]`)
// evaluates to [8, 3, 9]

You can use lambdex argument indices more than once or not at all.

Keywords

FAQs

Last updated on 17 Mar 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc