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

funtastic

v0.2.0

Published

Functional Programming library for me and you

Downloads

31

Readme

Funtastic

Functional Programming (FP) offers a paradigm shift that can fundamentally transform how we approach coding, problem-solving, and software architecture. The principles of FP emphasize immutability, pure functions, and higher-order functions, which collectively foster code that is more predictable, reusable, and easier to test.

Key Benefits of Functional Programming

  • Immutability: In FP, data is immutable by default. This means once a data structure is created, it cannot be modified. This eliminates a whole class of bugs related to state changes and side effects, making your code more predictable and easier to reason about.

  • Pure Functions: Functions in FP are pure, meaning they always produce the same output given the same input and have no side effects. This leads to more reliable and testable code since functions do not depend on or alter the state of the system.

  • Higher-Order Functions: FP leverages higher-order functions, which can take other functions as arguments or return them as results. This enables more abstract and concise code, allowing for powerful patterns like function composition and currying.

  • Declarative Code: FP encourages writing declarative code, which focuses on what to do rather than how to do it. This leads to clearer and more readable code, as the intention of the code is more apparent.

  • Concurrency and Parallelism: Due to immutability and pure functions, FP naturally lends itself to concurrent and parallel programming. Without mutable state, it becomes easier to run code in parallel without running into issues related to shared state.

Why Choose FP for Your Project?

Adopting FP principles can significantly enhance the quality and maintainability of your codebase. By emphasizing immutability and pure functions, FP helps in building software that is robust and less prone to bugs. The modular nature of functional code makes it easier to test and reuse, leading to more efficient development processes.

Install

npm i funtastic

Usage

import {
  Optional, Result, Effect, List, curry, compose, empty, is, match, map
} from 'funtastic';

// Using Optional
const person = Optional
  .of({ name: 'Alice', age: 30 })
  .map((x) => ({ ...x, age: x.age + 1 }))
  .map((x) => ({ ...x, name: 'Alice Cooper' }));

person.match({
  Some: console.log,
  None: () => 'Phew!'
}) // { name: 'Alice Cooper', age: 31 }

const getPersonByName = new Effect(async (name: string) => {
  const response = await fetch(`http://api.example.com/people?s=${mame}`)
  return Optional.of(await response.json())
})
  .map(transformSomethingInPerson)

getPersonByName
  .call('Alice')
  .map(applyAnotherTransformer)
  .match({
    Some: (x) => console.log(x) // { name: 'Alice Cooper', age: 31 }
    None: () => 'No person with that name'
  })