New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pico-lambda

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pico-lambda

native functional js

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-58.33%
Maintainers
2
Weekly downloads
 
Created
Source

pico-lambda

λ
Arrays the functional way
A 460b functional library based on native array methods
API stability

why pico-lambda

  • Pico: weighs less than 460 bytes gzipped.
  • Useful: takes most native JavaScript array methods and makes them immutable, curried, and composable.
  • Familiar: same names just curried and composable JavaScript Array..

Pico-lambda was made for the ES2015 Javascript Runtime. It has no dependencies.


Example

After installing via npm install:

const {
  concat,
  filter,
  map,
  reduce,
  compose
} = require('pico-lambda')

//concat
const arrayOne = [1, 2, 3];
const addTwo = concat([4, 5])
const result = addTwo(arrayOne)

// We can compose instead of chaining
compose(
  reduce((acc, val) => val + acc, 0),
  map(x => x * 2),
  filter(x => x > 5),
  concat([6, 7, 8])
)([1, 2, 3, 4, 5])

Api

compose :: ((e -> f), ..., (b -> c), (a -> b)) -> a -> f

Evaluates the provided functions, right to left, passing the return value of each function to the next in line. The initial function is passed the initial value provided to comopse. The output of the final function, in this case (e->f), is returned.

concat :: [a] -> ([a], ..., [a]) -> [a]

Concatenates two arrays

concat([4, 5])([1,2,3])    // => [1, 2, 3, 4, 5]
concat([4, 5])([1,2], [3]) // => [1, 2, 3, 4, 5]

See Array.concat (MDN)

copyWithin :: (Int, Int, Int) -> [a] -> [a]

Makes a shallow copy of part of an array and overwrites another location in the same with the copy. Size is kept constant.

See Array.copyWithin (MDN)

entries:: [a] -> [b]

Return an iterator over key, value pairs from the array.

See Array.entries (MDN)

every :: ((a, Int, [a]) -> Boolean) -> [a] -> Boolean

Applies predicate to all elements in array and returns false if any fail. The predicate function must at least take one parameter for each element but may optionally take an index and the entire array as 2nd and 3rd parameters, respectively.

See Array.every (MDN)

fill :: (a, Int, Int) -> [a] -> [a]

Fills a portion of the given array putting the same new value into each slot.

See Array.fill (MDN)

filter :: ((a, Int, [a]) -> Boolean) -> [a] -> [a]

Returns a new array containing only those elements of the given array that pass the given predicate.

See Array.filter (MDN)

find :: (a -> Boolean) -> [a] -> a | undefined

Finds and returns the first element in the given array that matches the given predicate. If no element passes, undefined is returned.

See Array.find (MDN)

findIndex :: (a -> Boolean) -> [a] -> Int

Returns the index of the first element in the given array that matches the given predicate. If no element passes, -1 is returned.

See Array.findIndex (MDN)

includes :: a -> [a] -> Boolean

Returns true if the given element is in the given array, otherwise false.

See Array.includes (MDN)

indexOf :: (a, Int) -> [a] -> Int

Returns the index of the given element if it is in the given array, otherwise -1. The 2nd parameter can be used to change where it starts looking.

See Array.indexOf (MDN)

join :: String -> [a] -> String

Converts each element of the array to a string and concatenates them together with the given string as a delimiter.

See Array.join (MDN)

keys :: [a] -> [Int]

Return an iterator over keys from the array.

See Array.keys (MDN)

lastIndexOf :: (a, Int) -> [a] -> Int

Works like indexOf but starts at the end and works backwards. The 2nd parameter can be used to tell it where to start working backwards from.

See Array.lastIndexOf (MDN)

map :: (a -> b) -> [a] -> [b]

Applies a function over each element in the given array, returning a new array with each functions results.

See Array.map (MDN)

pipe :: ((a -> b), (b -> c), ..., (e -> f)) -> a -> f

Takes an initial value that is passed to the first function in the parameter list. The return value of each subsequent function is passed to the following function. The return value of the last function is returned from pipe.

See Array.pipe (MDN)

pop :: [a] -> [a]

Returns a new array without the last item

See Array.pop (MDN)

push :: a -> [a] -> [a]

Returns a new array with the new element appended to the end of the original array.

See Array.push (MDN)

reduce :: ((a, b) -> a) -> a -> [b] -> a

Applies a function against an accumulator and each value of the array (from left-to-right), then returning the accumulator.

See Array.reduce (MDN)

reduceRight :: ((a, b) -> a) -> a -> [b] -> a

Applies a function against an accumulator and each value of the array (from right-to-left), then returning the accumulator.

See Array.reduceRight (MDN)

reverse :: [a] -> [a]

Returns a new array with the elements in reverse order.

See Array.reverse (MDN)

shift :: [a] -> [a]

Returns a new array with the first element removed.

See Array.shift (MDN)

slice :: (int, int) -> [a] -> [a]

Takes a slice from a given array and returns it as a new array.

See Array.slice (MDN)

splice :: (int, int, [a]) -> [a] -> [a]

Returns a new array with the indicated elements removed. An optional set of new elements can be inserted in their place.

See Array.splice (MDN)

some :: (a -> Boolean) -> [a] -> Boolean

Returns true if any element in the given array matches the given predicate.

See Array.some (MDN)

sort :: ((a, a) -> int) -> [a] -> [a]

Returns a copy of the original array with the values sorted. If a comparator function is provided it should return -1, 0 or 1 depending on whether the first element is less than, equal to or greater than the second, respectively. If no comparator is given, lexical sorting is used.

See Array.sort (MDN)

toLocaleString :: (String, Obj) -> [a] -> String

Converts each element of an array into a string based on current locale settings or locale options passed in. The resulting strings are appended together using commas.

See Array.toLocaleString (MDN)

toString :: [a] -> String

Converts each element of an array into a string and appends them together with a comma.

See Array.toString (MDN)

unshift :: [a] -> [a]

Returns a new copy of an array with the first element removed.

See Array.unshift (MDN)

Where are ...?

  • length - This is a property, not a method, so it doesn't really belong here.
  • forEach - This is inherently side-effect-y, it adds nothing that can't be done with filter, map and reduce.

If you don't agree with anything above that's great! Just log an issue so we can discuss.

Keywords

FAQs

Package last updated on 27 Jan 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc