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

futurity

v0.0.1

Published

Swiss Army Knife Fluture Based Data Structure

Downloads

4

Readme

Table of Contents

About The Project

This data structure is a wrapper for reusing reuse everyday mutable and effectfull promise based libs in a functional monadic future based fashion.

The data structure is a Fluture extension (so you can directly use all Fluture operators and API).

If Fluture moand wraps a computation that async resolve to a value, Futurity brigs tree data structures:

  • Reader e -> a : Reader monad used to lazy wrap a mutable effectfull lib (like knex or superagent for example).

    Is a lazy Product Type that enables the composition of computations that depend on a shared > environment (e -> a). The left portion, the e must be fixed to a type for all related computations. The right portion a can vary in its type. -- Crocks Dev

  • e -> e : Environment reducer function, used to transforms environment before run it in the computation Reader.

  • Reader a -> Future b : A lazy structure (another Reader Monad) that takes the result value of the collapsing of first reader monad as environment and return a Future instance. All fluture operators (map, chain, ap...) applied to the data structure transforms the yet to exists future instace wrapped by the this monad.

Built With

Futurity is implemented in a few lines of code that mix up some good libraries:

Getting Started

Installation

  1. Add Futurity to your project
yarn add futurity
  1. If not already in your project add peer dependencies

    yarn add fluture

Usage

You can look in tests for other examples.

Sample of knex wrapping.

import Knex from 'knex'
import { Futurity, coMap, envMap } from 'futurity'
import * as F from 'fluture'

const I = a => a
const pipe = (...args) => args.reduce((f, g) => x => g(f(x)))

const db = Knex({
    client: 'sqlite3',
    connection: {
        filename: 'tests/chinook.sqlite'
    },
    useNullAsDefault: true
})

// Futurity that wrap knex instance
const DbFuturity = (db, args) =>
    Futurity.lift(
        p => db(...args),
        qb => F.attemptP(() => qb)
    )

const query = pipe(
    coMap(qb => qb.where({ Composer: 'Nirvana' })),
    coMap(qb => qb.limit(2)),
    F.map(rows => rows.map(track => track.Name))
)(DbFuturity(db, ['Track']))

(async function(){
    const value = await F.promise(query)
    console.log(value)
})()

Output:

['Aneurysm', 'Smells Like Teen Spirit']

Sample of superagent wrapping

import request from 'superagent'
import { Futurity, coMap, envMap } from 'futurity'
import * as F from 'fluture'

const I = a => a
const pipe = (...args) => args.reduce((f, g) => x => g(f(x)))

// Futurity that wrap Superagent instance
const SaFuturity = method =>
    Futurity.lift(request[method], agent => F.attemptP(() => agent))

const query = pipe(
    envMap(() => 'https://jsonplaceholder.typicode.com/todos/1'),
    F.map(res => res.body),
    F.map(body => body.title),
    coMap(req => req.set('accept', 'json'))
)(SaFuturity('get'))

(async function(){
    const title = await F.promise(query)
    console.log(title)
})()

Output:

'delectus aut autem'

API

The data structure is a Fluture extension (so you can directly use all Fluture operators and API).

Exception for cache and hooks not yet implemented (but you can collapse a Futurity instance to a Fluture instance at you occorence).

In addition to standard Fluture functions we have:

Factories

Operators

Consuming / Collapsing Operators

Factories

lift(computation: e -> a, computationToFuture: a -> Future b)

Contruct a new Futurity Instance, environment is intialized to identity function.

Arguments:

  • computation: e -> a Function that takes the environment and return the target value.

  • computationToFuture: a -> Future b Function that takes the computation result and transform it to a future.

Returns: Futurity Instance

Operators

envMap(e -> e)

Environment reducer. Function to transform the initial environment.

Arguments:

  • pred: e -> e Function that has the current environment as input and return the new environment.

Returns: Futurity Instance


coMap((a, e) -> a)

Function to transform the wrapped effectfull object.

Arguments:

  • (a, e) -> a For your confort the environment is passed as second argumet so you can you it.

Returns: Futurity Instance


Consuming / Collapsing Operators

future(fty)

Make the futurity instance collapse to a Future instance (not yet resolved).

Arguments:

  • fty Futurity instance.

Returns: Future Instance


License

Distributed under the MIT License. See LICENSE for more information.

Contact

Fabiano Taioli - [email protected]

Project Link: https://github.com/FbN/futurity