Giter VIP home page Giter VIP logo

fp.macro's Introduction

fp.macro

npm version Linux macOS Windows compatible Build status Coverage status Dependency status Renovate enabled
Open in Gitpod Buy Me a Coffee PayPal Patreon

A zero-runtime functional programming babel macro.

fp.macro This is a build-time functional programming library that allows you to use high-level collection functions without a production dependency and without the runtime penalty that you have when using a dedicated library.

It does so by exposing a Babel macro that is evaluated at build time by babel-plugin-macros. So in the end you do not have a production dependency anymore, it's all in the generated Babel code.

Install

# npm
$ npm install fp.macro

# Yarn
$ yarn add fp.macro

Usage

Install babel-plugin-macros:

$ npm install babel-plugin-macros

The plugin is best used with the Babel pipeline operator, so optionally install this one as well:

$ npm install @babel/plugin-proposal-pipeline-operator

Then add the plugins to your babel config or create a .babelrc.json file:

{
  "plugins": [
    "babel-plugin-macros",
    ["@babel/plugin-proposal-pipeline-operator", { "proposal": "fsharp" }]
  ]
}

Create a JavaScript file and start mapping collections:

import { filter, join, map, mapValues } from 'fp.macro'

const myMap = map(x => x * 2)

console.log(myMap([1, 2]))
// [2, 4]

// Using pipeline operator
console.log(
  [1, 2, 3]
    |> map(x => x * 2)
    |> filter(x => x > 2)
    |> join(',')
)
// 4,6

console.log(
  { foo: { name: 'foo' }, bar: { name: 'bar' } }
    |> mapValues(x => x.name)
)
// { foo: 'foo', bar: 'bar' }

To run the files, you need to use Babel. You can either compile them using @babel/cli, or run them directly via @babel/node (which is not recommended for production though).

The library is currently in development, so for more insights into the available functions check out the source code.

Contribute

Are you missing something or want to contribute? Feel free to file an issue or a pull request! ⚙️

Support

Hey, I am Sebastian Landwehr, a freelance web developer, and I love developing web apps and open source packages. If you want to support me so that I can keep packages up to date and build more helpful tools, you can donate here:

Buy Me a Coffee  If you want to send me a one time donation. The coffee is pretty good 😊.
PayPal  Also for one time donations if you like PayPal.
Patreon  Here you can support me regularly, which is great so I can steadily work on projects.

Thanks a lot for your support! ❤️

License

MIT License © Sebastian Landwehr

fp.macro's People

Contributors

actions-user avatar dword-design avatar dword-design-honestly avatar renovate-bot avatar renovate[bot] avatar semantic-release-bot avatar

Stargazers

 avatar

Watchers

 avatar  avatar

fp.macro's Issues

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Missing name property in package.json.

The package.json's name property is required in order to publish a package to the npm registry.

Please make sure to add a valid name for your package in your package.json.


Good luck with your project ✨

Your semantic-release bot 📦🚀

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.