New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

tinyfunk

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tinyfunk

The tiniest of functional libraries

latest
Source
npmnpm
Version
1.7.3
Version published
Weekly downloads
582
-5.52%
Maintainers
1
Weekly downloads
 
Created
Source

tinyfunk

The tiniest of functional libraries.

npm version npm downloads gzip-size
Build Status Coverage Status

Documentation

Motivation

Most popular functional libraries, like Ramda, are quite large. To use them in a frontend project, it's common to import only the bits you need (to keep the bundle size down) like this:

const assoc = require('ramda/src/assoc')
const map   = require('ramda/src/map')
const merge = require('ramda/src/merge')
// etc.

But multiple require statements take up extra space, since many js code compression tools (including uglify-js) don't mangle strings. The AST overhead required to bundle the various modules adds an additional size penalty, not to mention the extra compute time to parse the twisted flow of the AST, which adds to a longer perceived load time.

tinyfunk takes a different approach. It exports a single module to minimize AST overhead and obviate the repeated require statements. You just destructure the functions you need in one go:

const { assoc, map, merge } = require('tinyfunk')

Where possible, it also composes more complex functions by reusing basic ones. A good example is compose, implemented as so:

const compose = unapply(flip(reduceRight(thrush)))

With uglify-es, this mangles down to the following. I doubt you'll find a smaller implementation.

const I=r(b(B(E)))

Caveat emptor

In an effort to keep tinyfunk lean and mean - and most of all, tiny - I've taken a few shortcuts.

  • None of the exported functions perform type-checking of arguments.
    If type-checking is a runtime debug tool you tend to lean on, then you'll need to look elsewhere.

  • Many of the function combinators only support unary functions.
    This includes compose, converge, juxt, pipe, thrush, etc. Unary functions are easily composable, readily portable, and so much simpler (ie: tinier) to support.

  • Unlike other popular FP libraries, each exported function only has a single job.
    For example, Ramda's map supports "mapping" over functors, objects, and even functions. In tinyfunk, those various jobs are supported instead by map, mapObj, and compose respectfully. So be sure to use the right tool for the job at hand.

API

If you've lived with FP long enough, you are likely familiar with most of the functions listed below. So I've opted to leave out the lengthy descriptions and include only the signatures. I'll be adding more functions as I need them, but if you see any of your favorites missing, just post an issue and I'll be sure to consider it.

FunctionSignature
addNumber -> Number -> Number
appenda -> [a] -> [a]
apply(a... -> b) -> [a] -> b
assock -> v -> { k: v } -> { k: v }
assocPath[k] -> v -> { k: v } -> { k: v }
call(a... -> b) -> a... -> b
compose((y -> z), ..., (a -> b)) -> a -> z
composeP((y -> Promise z), ..., (a -> Promise b)) -> a -> Promise z
concatSemigroup a => a -> a -> a
cond[[(a -> Boolean), (a -> b)]] -> a -> b
constanta -> () -> a
converge(b... -> c) -> [(a -> b)] -> a -> c
curry((a, b, ...) -> z) -> a -> b -> ... -> z
curryNNumber -> ((a, b, ...) -> z) -> a -> b -> ... -> z
defaultToa -> a -> a
dissock -> { k: v } -> { k: v }
dissocPath[k] -> { k: v } -> { k: v }
either(a -> Boolean) -> (a -> Boolean) -> (a -> Boolean)
evolve{ k: (v -> v) } -> { k: v } -> { k: v }
filter(a -> Boolean) -> [a] -> [a]
find(a -> Boolean) -> [a] -> a
flatten[a] -> [b]
flip(a -> b -> c) -> (b -> a -> c)
head[a] -> a
identitya -> a
ifElse(a -> Boolean) -> (a -> b) -> (a -> b) -> (a -> b)
indexBy(v -> k) -> [v] -> { k: v }
init[a] -> [a]
isConstructor -> a -> Boolean
joinString -> [a] -> String
juxt[(a -> b)] -> a -> [b]
keys{ k: v } -> [k]
last[a] -> a
length[a] -> Number
mapFunctor f => (a -> b) -> f a -> f b
mapObj(v -> k -> v) -> { k: v } -> { k: v }
matchRegExp -> String -> [String]
merge{ k: v } -> { k: v } -> { k: v }
multiplyNumber -> Number -> Number
nAryNumber -> (a... -> b) -> (a... -> b)
nota -> a
objOfk -> v -> { k: v }
omit[k] -> { k: v } -> { k: v }
partial(a... -> b) -> [a] -> a... -> b
partialRight(a... -> b) -> [a] -> a... -> b
path[k] -> { k: v } -> v
pathEq[k] -> v -> { k: v } -> Boolean
pick[k] -> { k: v } -> { k: v }
pipe((a -> b), ..., (y -> z)) -> a -> z
pipeP((a -> Promise b), ..., (y -> Promise z)) -> a -> Promise z
pluckk -> [{ k: v }] -> [v]
prependa -> [a] -> [a]
propk -> { k: v } -> v
propEqk -> v -> { k: v } -> Boolean
props[k] -> { k: v } -> [v]
reduceFoldable f => (b -> a -> b) -> b -> f a -> b
reduceObj(a -> v -> k -> a) -> a -> { k: v } -> a
reduceP(b -> a -> Promise b) -> b -> [a] -> Promise b
reduceRightFoldable f => (b -> a -> b) -> b -> f a -> b
reduceRightP(b -> a -> Promise b) -> b -> [a] -> Promise b
replaceRegExp -> String -> String -> String
sliceNumber -> Number -> [a] -> [a]
sort((a, a) -> Number) -> [a] -> [a]
sortByOrd b => (a -> b) -> [a] -> [a]
splitRegExp -> String -> [String]
tail[a] -> [a]
takeNumber -> [a] -> [a]
tap(a -> b) -> a -> a
testRegExp -> String -> Boolean
then(a -> Promise b) -> a -> Promise b
thrusha -> (a -> b) -> b
unapply([a] -> b) -> a... -> b
unary(a... -> b) -> (a -> b)
uniqBy(a -> String) -> [a] -> [a]
unita -> ()
unless(a -> Boolean) -> (a -> a) -> a -> a
useWith(b... -> c) -> [(a -> b)] -> a... -> c
values{ k: v } -> [v]
when(a -> Boolean) -> (a -> a) -> a -> a
zipObj[k] -> [v] -> { k: v }

Dependents

I use tinyfunk everyday to make cool things. Maybe you do, too. If so, let me know with a PR, and we can add your cool things to this list.

  • puddles - Tiny vdom app framework. Pure Redux. No boilerplate. - Built with ❤️ on tinyfunk.

Keywords

functional

FAQs

Package last updated on 27 Jun 2020

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