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

fronads

v0.18.0

Published

Frontend monads with consistent and beginner-friendly naming conventions.

Downloads

656

Readme

Fronads

fronads npm

Frontend monads with consistent and beginner-friendly naming conventions.

docs

What is a monad?

Monads are function composers. They let you compose functions together to control your program flow.

  • Monads let you map a function to a value.
  • Monads are only ever in one state at a time. Each of their methods returns either the same monad or a new one in a different state.

Almost monads

Monads are a specific combination of ideas that you probably already understand. Because of this it can be hard to understand the whole but easy to grasp the parts.

Some almost monad things to help you understand:

  • Promises are almost monads: They provide a consistent interface to structure the flow of async data
  • Promises are almost monads: They can only ever be in one state at a time. Resolved, Rejected.
  • Arrays are almost monads: They can always have a function mapped to their value, regardless of what they contain.
  • Array.map is almost monadic: It provides a level of immutability by returning a new array with the values changed.

All monads

All monads have these three methods. Some languages have different names for them, but their idea remains the same.

  • Unit
  • flatMap
  • map

Unit

Unit is the monad constructor. It takes a value and returns a new monad of that state. Because monads deal with program flow and most monads have sort of sub types that represent one or more the states. The Unit's purpose is to let you declare a single monad of a specific state. E.g.

Some/None Left/Right Fetching/Error/Success

function unitExample() {
    return test ? Some(value) : None();
}

The above function is consistent because it always returns a monad. However if test is true it will return aSome monad containing a value, otherwise it will return a None.

9/10 times you'd use the specific unit constructor for the monad you want but each monad does have a .unit method

flatMap

The second core function of a monad is Flatmap. It's not however the flatter version of map, in fact flatMap provideds the basis for map. Flatmap says I'll pass the current value to your function, you return me another monad.

Other terms: bind, chain

Fronads chooses flatMap/map because they pair nicely.

map

Map builds off both unit and Flatmap, and is essentially value => flatMap(Unit(value)). Map is a convenient flatMap. It knows that you probably want the same monad again and so automatically creates the one you want. Letting you do things like:

Some(person).map(person => person.age) 

The above statement will return a new some containing the persons age.