1.8.0 • Published 4 years ago

@mutantlove/m v1.8.0

Weekly downloads
15
License
BSD-3-Clause
Repository
github
Last release
4 years ago

CircleCI npm package version dev-badge Coverage Status

m

Point free style, functional library for Javascript

Experimental. Use Ramda.


"With" pattern

import { find, findWith, filterWith, is } from "@mutantlove/m"

const todos = [
  {id: 1, name: "lorem", tagId: 2,},
  {id: 2, name: "ipsum", tagId: null},
  {id: 3, name: "dolor", tagId: null},
]

find(item => item.id === 2)(todos)
// or
findWith({id: 2})(todos)
//=> {id: 2, name: "ipsum"}

// predicate style filter
filterWith({
    tagId: is // or "tagId: value => is(value)"
})(todos)
// [{id:1, name: "lorem", tagId: 2}]

|> pipe

There is no structure difference between pipe and compose, both will use the same building blocks to get from A to B.

A series of transformations over an initial input can be written as x -> f -> g -> result, piping, or as result = g(f(x)), composing. The difference is only syntactic. Input is the same, transformations and order of application are the same, the result will be the same.

Given that:

it makes sense to choose the syntactic more aligned with our intuition and context. The transformations are applied in a certain order with time as a medium - input -> t0 -> t1 -> tn -> output. The way is forward.

const { sep } = require("path")
const { pipe, compose, join, push, dropLast, split } = require("@mutantlove/m")

// Compose - g(f(x))
const renameFile = newName => filePath =>
  compose(
    join(sep), push(newName), dropLast, split(sep)
  )(filePath)

// Pipe - x -> f -> g
const renameFile = newName => filePath =>
  pipe(
    split(sep), dropLast, push(newName), join(sep)
  )(filePath)

// Using the pipeline operator, things are more expressive
const renameFile = newName => filePath =>
  filePath |> split(sep) |> dropLast |> push(newName) |> join(sep)

Install

npm install @mutantlove/m

Develop

git clone git@github.com:mutantlove/m.git && \
  cd m && \
  npm run setup

# run tests (any `*.test.js`) once
npm test

# watch `src` folder for changes and run test automatically
npm run tdd

Use

import { pipe, trim, split, dropLast, push, join } from "@mutantlove/m"

const removeTrailingSlash = source =>
  source[source.length - 1] === sep ? source.slice(0, -1) : source

const renameFile = newName => pipe(
  removeTrailingSlash,
  split(sep),
  dropLast,
  push(trim(sep)(newName)),
  join(sep)
)

Commit messages

Using Angular's conventions.

<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
BREAKING CHANGE: Half of features not working anymore
  • feat: A new feature
  • fix: A bug fix
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
  • refactor: A code change that neither fixes a bug nor adds a feature
  • perf: A code change that improves performance
  • test: Adding missing or correcting existing tests
  • chore: Changes to the build process or auxiliary tools and libraries such as documentation generation

Changelog

See the releases section for details.

1.8.0

4 years ago

1.7.0

4 years ago

1.6.0

4 years ago

1.5.0

4 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.31.0

5 years ago

0.30.1

5 years ago

0.30.0

5 years ago

0.29.1

5 years ago

0.23.0

5 years ago