funsenal
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

funsenal

An opinionated function programming arsenal. It is not a general purpose fp lib that offers the things you would expect from lodash or Ramda.

This is an experiment to make fp easier with the recurring patterns.

to start

npm i funsenal

examples

import {maps} from "funsenal"
 
suite("maps Tests", () => {
    before(() => {
        chai.should();
    });
 
    test("collect should be able to collect turples", () => {
        maps.collect([['hello', 1], ["world", 2]]).should.deep.equal({
            hello: 1,
            world: 2
        })
    });
 
    test("collect should be able to collect key-val pairs", () => {
        maps.collect([{ key: 'hello', val: 1 }, { key: 'world', val: 2 }]).should.deep.equal({
            hello: 1,
            world: 2
        })
    });
 
    test("pickMap should return a map with picked keys and applied mapping", () => {
        maps.pickMap({ hello: i => i + 2 }, { hello: 1, world: 2 }).should.deep.equal({
            hello: 3
        })
    });
 
    test("specMap should return a map that matches the spec by applying the mappings to the input", () => {
        maps.specMap({ greeting: m => m.world }, { hello: 1, world: 2 }).should.deep.equal({
            greeting: 2
        })
    });
 
    test("mergeMap should first apply the mappings and merge the output", () => {
        maps.mergeMap({ hello: 1, world: 2 },
            i => { return { hi: i.hello } },
            j => { return { oldWorld: j.world, newWorld:j.world + 1 } }).should.deep.equal({
                hi: 1,
                oldWorld: 2,
                newWorld: 3
            })
    });
});
 

Readme

Keywords

none

Package Sidebar

Install

npm i funsenal

Weekly Downloads

1

Version

0.2.0

License

ISC

Unpacked Size

16.1 kB

Total Files

27

Last publish

Collaborators

  • jackkcwong