Prelude.ls Functional Utility Library

1.2.1 · abandoned · verified Sun Apr 19

prelude.ls is a functionally oriented utility library designed to simplify common programming tasks by providing a rich set of curried functions. It is primarily written in LiveScript and serves as the recommended base library for LiveScript projects, although it is fully usable within standard JavaScript environments. The library offers a wide array of utilities for lists, objects, strings, functions, and numbers, emphasizing a functional programming paradigm with functions like `map`, `filter`, and `fold` readily available. The current stable version is 1.2.1. Given its last update approximately six years ago (around April 2020), its release cadence is effectively inactive, indicating it is no longer actively maintained. A key differentiator is its deep integration with and recommendation for the LiveScript ecosystem, providing a Haskell-like prelude module, and its consistent use of currying across most functions. It predates widespread modern JavaScript module systems and exclusively functions via CommonJS modules.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import `prelude-ls` using CommonJS and utilize its core functional programming utilities, including curried `map`, `filter`, `fold`, and an object-specific `Obj.map` function.

const P = require('prelude-ls');

// Example 1: Basic list mapping with a curried function
const addTwo = P.map(x => x + 2);
const numbers = [1, 2, 3, 4, 5];
const mappedNumbers = addTwo(numbers);
console.log('Mapped numbers:', mappedNumbers); // Expected: [3, 4, 5, 6, 7]

// Example 2: Filtering even numbers, demonstrating currying
const isEven = x => x % 2 === 0;
const filterEven = P.filter(isEven);
const evenNumbers = filterEven(numbers);
console.log('Even numbers:', evenNumbers); // Expected: [2, 4]

// Example 3: Folding (reducing) a list
const sum = P.fold((acc, x) => acc + x, 0);
const total = sum(numbers);
console.log('Sum of numbers:', total); // Expected: 15

// Example 4: Using an object-specific function
const data = { a: 1, b: 2, c: 3 };
const objMapValues = P.Obj.map(x => x * 10);
const mappedObject = objMapValues(data);
console.log('Mapped object:', mappedObject); // Expected: { a: 10, b: 20, c: 30}

view raw JSON →