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

day-dream

v0.1.3

Published

A playground collection of fantasy-land types that I find useful

Downloads

6

Readme

day-dream

An playground collection of Fantasy Land types that I find useful.

yarn add day-dream

Box

Just a container where to put any value that allows you to then map over it. Apparently this is called the "identity functor". Taken straight from the examples, I’m putting it in a lib because I couldn’t find it anywhere in fantasy-land or related libs.

import {Box} from 'day-dream'
// or import Box from 'day-dream/Box'

Box({a: 'b'})
  .map({a} => a)
  .map(s => s.toUpperCase())
  .fold(x => x) === 'B'

createStoreType

This function allows you to create a Redux inspired Store type that is a Monoid, Foldable and Functor.

An example is worth a thousand explanations:

import {createStoreType} from 'day-dream'
// or import createStoreType from 'day-dream/createStoreType'

const CounterStore = createStoreType(
  (state, action) => {
    switch (action.type) {
      case 'INCREMENT':
        return {
          value: state.value + 1
        }

      case 'DECREMENT':
        return {
          value: state.value - 1
        }

      default:
        return state
    }
  },
  {
    value: 0
  }
)

const store = CounterStore.empty()

store
  .concat(CounterStore({type: 'INCREMENT'}))
  .concat(CounterStore({type: 'INCREMENT'}))
  .concat(CounterStore({type: 'INCREMENT'}))
  .concat(CounterStore({type: 'DECREMENT'}))
  .fold(({value}) => value) === 2

map does what you would expect

Func

Wrap a function to support composition via concat, apply higher-order functions to it via map and run it with fold.

import {Func} from 'day-dream'
// or import Func from 'day-dream/Func'

const addTuple = Func(([a, b]) => a + b)

addTuple.concat(Func(x => x * 3)).fold([2, 5]) === 21

MergeMap

This is a type very similar to immutable-ext’s Map, with the difference that the concat function of this type does an object assign between the two MergeMaps instead of running concat on every value.

import {deepEqual} from 'assert'
import {MergeMap} from 'day-dream'
// or import MergeMap from 'day-dream/MergeMap'

deepEqual(
  MergeMap({a: 1}).concat(MergeMap({b: 2})).fold(x => x),
  {a: 1, b: 2}
)

deepEqual(
  MergeMap({a: 1, b: 2}).concat(MergeMap({b: 3, c: 4})).fold(x => x),
  {a: 1, b: 3, c: 4}
)

PairList

An object structure type that treats the object as an unordered set of tuples [String, a] where String is the key.

concat will merge, exactly like MergeMap but both map and fold take a function with the signature ([String, a]) => [String, a] as an argument.

import {PairList} from 'day-dream'
// or import PairList from 'day-dream/PairList'

deepEqual(
  PairList({a: 1})
    .concat(PairList({b: 2}))
    .map(([key, value]) => [key.toUpperCase(), value + 1])
    .fold(([key, value]) => [key, value * 2]),
  {A: 4, B: 6}
)

Credits

  • https://github.com/DrBoolean
  • https://github.com/fantasyland/fantasy-land

License

MIT