All Projects → flintinatux → tinyfunk

flintinatux / tinyfunk

Licence: other
The tiniest of functional libraries

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to tinyfunk

Graceful Server
Tiny (~5k), KISS, dependency-free Node.JS library to make your API more graceful
Stars: ✭ 173 (+565.38%)
Mutual labels:  tiny
htcc
🐤 A tiny C language compiler (x86-64) (WIP)
Stars: ✭ 31 (+19.23%)
Mutual labels:  tiny
elk
A low footprint JavaScript engine for embedded systems
Stars: ✭ 1,458 (+5507.69%)
Mutual labels:  tiny
Webpack Nano
A teensy, squeaky 🐤 clean Webpack CLI
Stars: ✭ 199 (+665.38%)
Mutual labels:  tiny
Just
A library of dependency-free JavaScript functions that do just do one thing.
Stars: ✭ 3,837 (+14657.69%)
Mutual labels:  tiny
tiny httpd
Minimal HTTP server using good old threads + blocking IO, with a small request router.
Stars: ✭ 64 (+146.15%)
Mutual labels:  tiny
Tinn
A tiny neural network library
Stars: ✭ 1,944 (+7376.92%)
Mutual labels:  tiny
minidenticons
Super lightweight SVG identicon (icon avatar) generator
Stars: ✭ 89 (+242.31%)
Mutual labels:  tiny
Tic 80
TIC-80 is a fantasy computer for making, playing and sharing tiny games.
Stars: ✭ 3,176 (+12115.38%)
Mutual labels:  tiny
piecewiselinear
tiny linear interpolation library for go (factored out from https://github.com/sgreben/yeetgif)
Stars: ✭ 23 (-11.54%)
Mutual labels:  tiny
Tinycreditcard
A clear and animated credit card input workflow implement
Stars: ✭ 236 (+807.69%)
Mutual labels:  tiny
Cwebsocket
cWebsocket is lightweight websocket server library
Stars: ✭ 241 (+826.92%)
Mutual labels:  tiny
lvg
Lion Vector Graphics
Stars: ✭ 106 (+307.69%)
Mutual labels:  tiny
Pristine
Vanilla javascript form validation micro-library
Stars: ✭ 197 (+657.69%)
Mutual labels:  tiny
embed
An embeddable, tiny Forth interpreter with metacompiler.
Stars: ✭ 80 (+207.69%)
Mutual labels:  tiny
Bahunya
10KB classless CSS framework with responsive typography, navbar, syntax highlighting, etc.
Stars: ✭ 170 (+553.85%)
Mutual labels:  tiny
tinyusd
A really small getting-started project for USD on Windows.
Stars: ✭ 29 (+11.54%)
Mutual labels:  tiny
ctxmenu
Tiny and customizable context menu generator
Stars: ✭ 20 (-23.08%)
Mutual labels:  tiny
Tiny-Basic
A tiny and basic TINY-BASIC interpreter
Stars: ✭ 33 (+26.92%)
Mutual labels:  tiny
CalDOM
An agnostic, reactive & minimalist (3kb) JavaScript UI library with direct access to native DOM.
Stars: ✭ 176 (+576.92%)
Mutual labels:  tiny

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.

  1. 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.

  2. 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.

  3. 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.

Function Signature
add Number -> Number -> Number
append a -> [a] -> [a]
apply (a... -> b) -> [a] -> b
assoc k -> 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
concat Semigroup a => a -> a -> a
cond [[(a -> Boolean), (a -> b)]] -> a -> b
constant a -> () -> a
converge (b... -> c) -> [(a -> b)] -> a -> c
curry ((a, b, ...) -> z) -> a -> b -> ... -> z
curryN Number -> ((a, b, ...) -> z) -> a -> b -> ... -> z
defaultTo a -> a -> a
dissoc k -> { 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
identity a -> a
ifElse (a -> Boolean) -> (a -> b) -> (a -> b) -> (a -> b)
indexBy (v -> k) -> [v] -> { k: v }
init [a] -> [a]
is Constructor -> a -> Boolean
join String -> [a] -> String
juxt [(a -> b)] -> a -> [b]
keys { k: v } -> [k]
last [a] -> a
length [a] -> Number
map Functor f => (a -> b) -> f a -> f b
mapObj (v -> k -> v) -> { k: v } -> { k: v }
match RegExp -> String -> [String]
merge { k: v } -> { k: v } -> { k: v }
multiply Number -> Number -> Number
nAry Number -> (a... -> b) -> (a... -> b)
not a -> a
objOf k -> 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
pluck k -> [{ k: v }] -> [v]
prepend a -> [a] -> [a]
prop k -> { k: v } -> v
propEq k -> v -> { k: v } -> Boolean
props [k] -> { k: v } -> [v]
reduce Foldable 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
reduceRight Foldable f => (b -> a -> b) -> b -> f a -> b
reduceRightP (b -> a -> Promise b) -> b -> [a] -> Promise b
replace RegExp -> String -> String -> String
slice Number -> Number -> [a] -> [a]
sort ((a, a) -> Number) -> [a] -> [a]
sortBy Ord b => (a -> b) -> [a] -> [a]
split RegExp -> String -> [String]
tail [a] -> [a]
take Number -> [a] -> [a]
tap (a -> b) -> a -> a
test RegExp -> String -> Boolean
then (a -> Promise b) -> a -> Promise b
thrush a -> (a -> b) -> b
unapply ([a] -> b) -> a... -> b
unary (a... -> b) -> (a -> b)
uniqBy (a -> String) -> [a] -> [a]
unit a -> ()
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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].