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

koeus

v0.3.3

Published

A small functional library.

Downloads

27

Readme

Koeus

A small functional library for javascript

About

The K Combinator + Coeus (Greek Titan of Intellect) === Koeus. I found an alternative spelling of Coeus, spelled KOIOS and facepalmed. This is a small utility library that has little to no dependencies. If you need something greater, I suggest you reach for Ramda or if you've jumped into the deep end of the pool you could look at Folktale.

If you're still unsatisfied, you could look at Elm or for the purists, Purescript.

TOC

Installation

First:

npm install koeus

Example of usage:

Note: All non-unary functions that do not have a variable number of arguments (such as pipe) are auto curried, so that you can apply some or all arguments to it.

import { map } from 'koeus'

const xs = map(x => x + 1, [1,2,3]) // [2,3,4]

// or, because map is auto curried

const addOne = x => x + 1
const mapAddOne(addOne)
const ys = mapAddOne([1,2,3]) // [2,3,4]

Functions

curry

Auto curries a function so that some or all of the arguments can be supplied.

    import { curry } from 'koeus'

    const add = (x,y) => x + y
    const curriedAdd = curry(add)

    const someArguments = add(1)(2)
    const allArguments = add(1,2)

pipe

Composes unary functions from left to right.

    import { pipe, curry } from 'koeus'

    const pipeline = pipe(x => x + 1, x => x + 2) // x => x + 3

    const four = pipeline(1) // 4

    // If you have a function with multiple arguments that you want to pipe
    // you can curry the function and partially apply it to make it an unary function.

    //ex:
    const add  = curry((x,y) => x + y)
    const addOne = add(1)
    const addTwo = add(2)
    const addThree = pipe(addOne, addTwo)
    const four = addThree(1) // 4

K

Accepts two arguments and ignores the second you give it. The name comes from the K combinator in combinatory logic.

    import { K } from 'koeus'

    const four = K(4,2) // 4

Id

Unary function that returns the argument you give it.

    import { Id } from 'koeus'

    const x = Id(1) // 1

Logic

combineAnd

Folds a list of booleans using logical conjunction (AND)

    import { combineAnd } from 'koeus'

    const t = combineAnd([true,true,true]) // true
    const f = combineAnd([true,true,false]) // false

combineOr

Folds a list of booleans using logical disjunction (OR)

    import { combineOr } from 'koeus'

    const t1 = combineOr([true,true,true]) // true
    const t2 = combineOr([true,false,true]) // true
    const f = combineOr([false,false,false]) // false

combinePreds

Takes a list of predicates and returns a predicate that's the conjunction of all of them.

    import { combinePreds } from 'koeus'

    const preds = combinePreds(x => x % 2 === 0, x => x < 10)
    const result = [1,2,14,4].filter(preds) // [2,4]

Lists

map

Accepts a function, then a functor (in this case a list) and runs the function over the list.

    import { map } from 'koeus'

    const Box = x => ({
        map: f => Box(f(x))
    })

    const addOne = map(x => x + 1) // collection => collection.map(x => x + 1)

    const mapList = addOne([1,2,3]) // [2,3,4]
    const mapBox = addOne(Box(1)) // Box holding the value 2

flatten

Flattens a list one level.

    import { flatten } from 'koeus'

    const flattened = flatten([[2],[3],[4]]) // [2,3,4]

deepFlatten

Flattens a list recursively n-depth levels.

    import { deepFlatten } from 'koeus'

    const flattened = deepFlatten([[2, [3]],[3,[3,4]],[4]]) // [2,3,3,3,4,4]

partition

Take a predicate, then a list and returns an array of two arrays, the first of which passes the predicate passed in, the second which does not.

    import { partition } from 'koeus'

    const arr = [1,2,3,4]
    const isEven = x => x % 2 === 0
    const partitioned = partition(isEven)(arr) // [[2,4],[1,3]]

Objects

entries

Takes an object, then returns an array containing the values from it's keys, one level deep.

    import { entries } from 'koeus'

    const obj = { id: 2, name: 'Will'}
    const vals = entries(obj) // [2, Will]

Transducers

transMap

Takes a transformation function, then returns a reducing function to pass to a reduce function on a list.

    import { transMap } from 'koeus'

    const reducingFunction = transMap(x => x + 1)

    const newArray = [5,5].reduce(reducingFunction, []) // [6,6]

transFilter

Takes a predicate function, then returns a reducing function to pass to a reduce function on a list.

    import { transMap } from 'koeus'

    const reducingFunction = transFilter(x => x % 2 === 0)
    const result = [5,2,10].reduce(reducingFunction, []) // [2,10]

Versioning

We use SemVer for versioning.

License

This project is licensed under the MIT License