npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@koy/core

v0.16.12

Published

Functions' and Functors' library.

Downloads

15

Readme

@koy/core

Functions' and Functors' library.

Why I write this library?

About javascript functional programming, we already have ramda.js、immutable.js、folktale and so on. I write this library is based on my view on javascript functional programming, since one hundred readers have one hundred Hamlett, I write this just for my functional programming style. Of course, If you'd like it, that would be a great happiness for me!

How do I design this library?

As you know, our mostly used data types are Number、String、Boolean、null、undefined、Array and Object. And since es6+ comes on, we may use Symbol、Set、map、ArrayBuffer and so on. So in this library, I just design this based on the first seven data types, and for the second data types, since we use rarely, if you'd like, you can design the function based on this by yourself.

About immutable data, I design not like immutable.js, although that costs less performance, But it designs data types By it's way, not simular to javascript data types, so we used Object.assign and Array.prototype.concat to realize it. I generate a new data based on old data to replace of mutable data.

About Functor, I encourage you use it more and design it based on yourself. Here, i just design four mostly used Functors -- Identity、Maybe、IO and Task.

All Functions

Here are functions that i design in this library.

I divide them into Function、Functor、List、Logic、Math、Object、Relation、String and Type.

Function

  • __:: functional parameter placeholder
  • always:: a -> (*... -> a)
  • applyTo:: a -> (a -> b) -> b
  • ascend:: Ord b => (a -> b) -> a -> a -> Number
  • binary:: (*... -> c) -> ((a, b) -> c)
  • comparator:: ((a, b) -> Boolean) -> ((a, b) -> Number)
  • compose:: ((y -> z) -> (x -> y) -> ... -> (a -> b)) -> (a -> z)
  • converge:: [(x1, x2, ...) -> a, (x1, x2, ...) -> b, ..., (x1, x2, ...) -> m] -> ((a, b, ..., m) -> n) -> ((x1, x2, ...) -> n)
  • curry:: ((a, b, c, ..., m) -> n) -> ((a, b, c, ..., m) -> n)
  • descend:: Ord b => (a -> b) -> a -> a -> Number
  • empty:: a -> a | undefined
  • flip:: ((a, b, ..., m) -> n) -> ((b, a, ..., m) -> n)
  • id:: a -> a
  • invoker:: Number -> String -> ((a, b, ..., m, Object) -> *)
  • juxt:: [(a, b, ..., m) -> n] -> ((a, b, ..., m) -> [n])
  • nAry:: Number -> ((a, b, ..., m) -> n) -> ((a, b, ..., m) -> n)
  • o:: (b -> c) -> (a -> b) -> a -> c
  • sequence:: ((a, b, ..., m) -> () -> n) -> ((a, b, ..., m) -> n)
  • tap:: (a -> *) -> a -> a
  • unary:: (*... -> b) -> (a -> b)

Functor

  • Identity:: always use for containing a value in a box
  • IO:: always use for IO(input and output) and side effects
  • Maybe:: always use for dividing value for two typs(null type and no null type)
  • Task:: always use for asynchronous task and side effects
  • ap:: Functor f => f (a -> b) -> f a -> f b
  • chain:: Functor f => (a -> f b) -> f a -> f b
  • extract:: Functor f => f a -> a
    • :: [a] -> [a]
  • fork:: Task T => (a -> c) -> (a -> b) -> T a -> ()
  • identity:: Identity I => I a -> a
  • join:: Functor f => f (f a) -> f a
  • lift:: Functor f => ((a, b, ..., m) -> n) -> ((f a, f b, ..., f m) -> f n)
  • map:: Functor f => (a -> b) -> f a -> f b
  • maybe:: Maybe m => b -> (a -> b) -> m a -> b
  • of:: Functor f => f -> a -> f a
  • unsafePerformIO:: IO I => I a -> a

List

  • adjust:: Number -> (a -> a) -> [a] -> [a]
  • all:: (a -> Boolean) -> [a] -> Boolean
  • any:: (a -> Boolean) -> [a] -> Boolean
  • aperture:: Number -> [a] -> [[a]]
  • append:: a -> [a] -> [a]
  • contains:: a -> [a] -> Boolean
  • filter:: (a -> Boolean) -> [a] -> [a]
  • find:: (a -> Boolean) -> [a] -> a | undefined
  • findIndex:: (a -> Boolean) -> [a] -> Number
  • foldl:: ((a, b) -> a) -> a -> [b] -> a
  • foldr:: ((b, a) -> a) -> a -> [b] -> a
  • fromPairs:: [[k, v]] -> {k: v}
  • indexOf:: a -> [a] -> Number
  • insert:: Number -> a -> [a] -> [a]
  • insertAll:: Number -> [a] -> [a] -> [a]
  • intercalate:: String -> [a] -> String
  • none:: (a -> Boolean) -> [a] -> Boolean
  • pair:: b -> a -> [a, b]
  • prepend:: a -> [a] -> [a]
  • range:: Number -> Number -> [Number]
  • reject:: (a -> Boolean) -> [a] -> [a]
  • remove:: Number -> Number -> [a] -> [a]
  • sort:: ((a, a) -> Number) -> [a] -> [a]
  • transpose:: [[a]] -> [[a]]
  • uniq:: [a] -> [a]
  • update:: Number -> a -> [a] -> [a]
  • xprod:: [b] -> [a] -> [[a, b]]
  • zip:: [b] -> [a] -> [[a, b]]
  • zipWith:: ((b, a) -> c) -> [b] -> [a] -> [c]

Logic

  • allPass:: [(a, b, ... m) -> Boolean] -> ((a, b, ..., m) -> Boolean)
  • and:: b -> a -> a | b
  • anyPass:: [(a, b, ..., m) -> Boolean] -> ((a, b, ..., m) -> Boolean)
  • both:: ((a, b, ..., m) -> Boolean) -> ((a, b, ..., m) -> Boolean) -> ((a, b, ..., m) -> Boolean)
  • complement:: ((a, b, ..., m) -> n) -> ((a, b, ..., m) -> Boolean)
  • either:: ((a, b, ..., m) -> Boolean) -> ((a, b, ..., m) -> Boolean) -> ((a, b, ..., m) -> Boolean)
  • not:: * -> Boolean
  • or:: b -> a -> a | b

Math

  • add:: Number -> Number -> Number
  • dec:: Number -> Number
  • divide:: Number -> Number -> Number
  • inc:: Number -> Number
  • mean:: [Number] -> Number
  • median:: [Number] -> Number
  • mod:: Number -> Number -> Number
  • multiply:: Number -> Number -> Number
  • negate:: Number -> Number
  • subtract:: Number -> Number -> Number

Object

  • assoc:: k -> v -> {k: v} -> {k: v}
  • assocPath:: [k] -> v -> {k: v} -> {k: v}
  • dissoc:: k -> {k: v} -> {k: v}
  • dissocPath:: [k] -> {k: v} -> {k: v}
  • entries:: {k: v} -> [[k, v]]
  • has:: k -> {k: v} -> Boolean
  • keys:: {k: v} -> [k]
  • lens:: (s -> a) -> ((a, s) -> s) -> Lens s a
    • Lens s a = Functor f => (a -> f a) -> s -> f s
  • lensIndex:: Number -> Lens s a
    • Lens s a = Functor f => (a -> f a) -> s -> f s
  • lensPath:: [k] -> Lens s a
    • Lens s a = Functor f => (a -> f a) -> s -> f s
  • lensProp:: k -> Lens s a
    • Lens s a = Functor f => (a -> f a) -> s -> f s
  • merge:: {k: v} -> {k: v} -> {k: v}
  • omit:: [k] -> {k: v} -> {k: v}
  • omitBy:: ((v, k) -> Boolean) -> {k: v} -> {k: v}
  • over:: Lens s a -> (a -> a) -> s -> s
    • Lens s a = Functor f => (a -> f a) -> s -> f s
  • path:: [k] -> {k: v} -> v | undefined
  • pick:: [k] -> {k: v} -> {k: v}
  • pickBy:: ((v, k) -> Boolean) -> {k: v} -> {k: v}
  • project:: [k] -> [{k: v}] -> [{k: v}]
  • prop:: k -> {k: v} -> v | undefined
  • set:: Lens s a -> a -> s -> s
    • Lens s a = Functor f => (a -> f a) -> s -> f s
  • toPairs:: {k: v} -> [[k, v]]
  • values:: {k: v} -> [v]
  • view:: Lens s a -> s -> a
    • Lens s a = Functor f => (a -> f a) -> s -> f s

Relation

  • difference:: [a] -> [a] -> [a]
  • differenceBy:: (a -> String) -> [a] -> [a] -> [a]
  • equals:: a -> a -> Boolean
  • equalsBy:: (a -> b) -> a -> a -> Boolean
  • gt:: Ord a => a -> a -> Boolean
  • gte:: Ord a => a -> a -> Boolean
  • intersection:: [a] -> [a] -> [a]
  • intersectionBy:: (a -> String) -> [a] -> [a] -> [a]
  • lt:: Ord a => a -> a -> Boolean
  • lte:: Ord a => a -> a -> Boolean
  • max:: Ord a => a -> a -> a
  • maxBy:: Ord b => (a -> b) -> a -> a -> a
  • min:: Ord a => a -> a -> a
  • minBy:: Ord b => (a -> b) -> a -> a -> a
  • union:: [a] -> [a] -> [a]
  • unionBy:: (a -> String) -> [a] -> [a] -> [a]

String

  • match:: RegExp | String -> String -> [String]
  • replace:: RegExp | String -> String | (($0, $1, ..., index, String) -> String) -> String -> String
  • split:: String -> String -> [String]
  • test:: RegExp -> String -> Boolean
  • toLower:: String -> String
  • toString:: * -> String
  • toUpper:: String -> String
  • trim:: String -> String

LIst && String

  • concat:: [a] -> [a] -> [a]
    • :: String -> String -> String
  • head:: [a] -> a | undefined
    • :: String -> String
  • init:: [a] -> [a]
    • :: String -> String
  • last:: [a] -> a | undefined
    • :: String -> String
  • length:: [a] -> Number
    • :: String -> Number
  • nth:: Number -> [a] -> a | undefined
    • :: Number -> String -> String
  • reverse:: [a] -> [a]
    • :: String -> String
  • slice:: Number -> Number -> [a] -> [a]
    • :: Number -> Number -> String -> String
  • tail:: [a] -> [a]
    • :: String -> String

Type

  • is:: * -> String