https://github.com/drager/carrying
A functional JavaScript library that carries you towards happier and better code.
https://github.com/drager/carrying
Last synced: 4 months ago
JSON representation
A functional JavaScript library that carries you towards happier and better code.
- Host: GitHub
- URL: https://github.com/drager/carrying
- Owner: drager
- Created: 2016-04-30T09:01:01.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-06-06T17:09:10.000Z (over 9 years ago)
- Last Synced: 2025-08-10T06:21:31.655Z (5 months ago)
- Language: TypeScript
- Homepage: http://drager.github.io/carrying/
- Size: 302 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Carrying
[](https://travis-ci.org/drager/carrying)
A functional JavaScript library that carries you towards happier and better code.
## Why?
Because JavaScript (as is at the moment) lacks some great functions built into the language.
A lot of other languages provides similar functions that this library provides.
Mainly functional languages, which this library has taken it's inspiration from. So this is simply a
functional JavaScript library which provides some useful functions that JavaScript currently lacks.
## Installation
```
npm install --save carrying
```
## Usage
Just import the functions you want to use:
```js
import {concat, intersperse, uncons, range, transpose} from 'carrying'
uncons(range(1, 11)) // => [[1], [2, 3, 4, 5, 6, 7, 8, 9, 10]]
uncons([1, 2, 3]) //=> [[1], [2, 3]]
uncons([]) //=> undefined
uncons('abc') //=> [['a'], ['b', 'c']]
uncons('ze') // => [['z'], ['e']]
uncons('q') // => ['q']
uncons('') //=> undefined
range(1, 3) // => [1, 2]
range(5, 11) // => [5, 6, 7, 8, 9, 10]
range(10, 9) // => []
range(2, 2) // => []
range(1, 10, 2) // => [1, 3, 5, 7, 9]
transpose([[1, 2, 3], [4, 5, 6]]) // => [[1, 4], [2, 5], [3, 6]]
transpose([[10, 11], [20], [], [30, 31, 32]]) // => [[10, 20, 30], [11, 31], [32]]
concat(intersperse(' ', ['intersperse', 'is', 'a', 'fun', 'function', '!'])) // => 'intersperse is a fun function !'
```
Any carrying module can be imported individually if you prefer that:
```js
import {takeWhile} from 'carrying/lib/takeWhile'
takeWhile(a => a < 3, [1, 2, 3, 4, 1, 2, 3, 4]) // => [1, 2]
```
## Documentation
Documentation is available online at: http://drager.github.io/carrying/