Git Product home page Git Product logo

funcode's Introduction

Functional Programming Functions

This project is a collection of functional programming functions written in TypeScript. The functions are designed to be composable and reusable, allowing you to build complex data transformations and processing pipelines.

Installation

To use these functions in your project, you can install them via npm:

npm install funcode

Usage

To use a function, you can import it from the package:

import { pipe } from 'funcode';

const add = (b: number) => (a: number) => a + b;
const square = (n: number) => n * n;

const result = pipe(2, add(3), square); // 25

Functions

createPipe

Creates a new function that applies a series of operations to a value in sequence.

import { createPipe } from 'funcode';

const add = (b: number) => (a: number) => a + b;
const square = (n: number) => n * n;

const myPipe = createPipe(add(3), square);
const result = myPipe(2); // 25

pipe

Applies a series of operations to a value in sequence.

import { pipe } from 'funcode';

const add = (b: number) => (a: number) => a + b;
const square = (n: number) => n * n;

const result = pipe(2, add(3), square); // 25

tap

Executes a side effect and returns the original value, ideal for debugging.

import { tap } from 'funcode';
import { add, square } from './';

const log = (value: any) => console.log(value);

const result = pipe(2, tap(log), add(3), square); // 25

when

A collection of functions that receive a function and execute it if the value matches the condition.

import { eq, gt, gte, lt, lte } from 'funcode/when';

const result = pipe(2, eq(2, (val) => val * 2), gte(4, (val) => val * 2)); // 8

funcode's People

Contributors

coldens avatar

Watchers

 avatar

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.