🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

@hanshi/array-typeclass

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hanshi/array-typeclass

A package providing type-class implentations such as monad and traversable to the native javascript array.

latest
Source
npmnpm
Version
0.0.6
Version published
Weekly downloads
7
-46.15%
Maintainers
1
Weekly downloads
 
Created
Source

@hanshi/array-typeclass

import * as AT from '@hanshi/array-typeclass';
import { _ } from '@hanshi/prelude';

const add = (n: number) => n + 1;

console.log('fmap add [1,2,3,4,5] = ', AT.fmap(add, [1, 2, 3, 4, 5]));

const linear = (a: number, x: number, b: number) => a * x + b;

console.log(
    'linear <$> [-1, 0, 1, 2] <*> [-2, -1, 0, 1, 2, 3] <*> [-1, 0, 1] = ',
    AT.tie(
        AT.tie(AT.fmap(linear, [-1, 0, 1, 2]), [-2, -1, 0, 1, 2, 3]),
        [-1, 0, 1]
    )
);

const liftedLinear = AT.lift(linear);

console.log(
    'liftedLinear [-1, 0, 1, 2] [-2, -1, 0, 1, 2, 3] [-1, 0, 1] = ',
    liftedLinear([-1, 0, 1, 2], [-2, -1, 0, 1, 2, 3], [-1, 0, 1])
);

const limitedLinear = (a: number, b: number) =>
    AT.tie(AT.fmap(_(linear, a), [-2, -1, 0, 1, 2, 3, 4, 5]), AT.pure(b));

for (const i of [-1, 0, 1])
    for (const j of [-2, 0, 3])
        console.log(`limitedLinear(${i}, ${j})`, limitedLinear(i, j));

console.log(
    'limitedLinear =<< [-1,0,1] <<= [-2, 0 ,3 ] = ',
    AT.warp([-2, 3], AT.warp([-1, 1], limitedLinear))
);

console.log(
    'limitedLinear =<< [-1,0,1] <<= [-2, 0 ,3 ] = ',
    AT.warp([-1, 1], limitedLinear)(5)
);

Keywords

hanshi

FAQs

Package last updated on 09 May 2023

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