All Projects → evilsoft → Crocks

evilsoft / Crocks

Licence: isc
A collection of well known Algebraic Data Types for your utter enjoyment.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Crocks

Language Ext
C# functional language extensions - a base class library for functional programming
Stars: ✭ 3,964 (+164.09%)
Mutual labels:  monad, functor, monoid
function-composition-cheatsheet
Composition of Functions
Stars: ✭ 24 (-98.4%)
Mutual labels:  composition, monad, functor
cpsfy
🚀 Tiny goodies for Continuation-Passing-Style functions, fully tested
Stars: ✭ 58 (-96.14%)
Mutual labels:  composition, monad, functor
Bow
🏹 Bow is a cross-platform library for Typed Functional Programming in Swift
Stars: ✭ 538 (-64.16%)
Mutual labels:  monad, functor, composition
Mostly Adequate Guide Chinese
函数式编程指北中文版
Stars: ✭ 2,093 (+39.44%)
Mutual labels:  monad, functor, curry
kudojs
A utility library to write code in functional programming style in Javascript
Stars: ✭ 22 (-98.53%)
Mutual labels:  composition, functor, curry
functional-structures-refactoring-kata
Starting code and proposed solution for Functional Structures Refactoring Kata
Stars: ✭ 31 (-97.93%)
Mutual labels:  composition, monad, functor
J-Curry
A Java library that enables applying Functional Programming concepts like currying and partial application for functions, also it supports types like Either, Try, etc... using RxJava 2 interfaces, compatible with Java 7 and above
Stars: ✭ 17 (-98.87%)
Mutual labels:  monad, functor, curry
fpEs
Functional Programming for EcmaScript(Javascript)
Stars: ✭ 40 (-97.34%)
Mutual labels:  monad, curry
invokable
Objects are functions! Treat any Object or Class as a Proc (like Enumerable but for Procs).
Stars: ✭ 40 (-97.34%)
Mutual labels:  composition, curry
Scriptum
A fool's scriptum on functional programming
Stars: ✭ 346 (-76.95%)
Mutual labels:  monad, composition
apropos
Fast strong typed 'Either' data structure for typescript and flow
Stars: ✭ 20 (-98.67%)
Mutual labels:  monad, adt
Learn Fp
learn-by-doing course/tutorial for functional programming on scala
Stars: ✭ 548 (-63.49%)
Mutual labels:  monad, functor
Fluokitten
Category theory concepts in Clojure - Functors, Applicatives, Monads, Monoids and more.
Stars: ✭ 408 (-72.82%)
Mutual labels:  monad, functor
Category Theory
An axiom-free formalization of category theory in Coq for personal study and practical work
Stars: ✭ 562 (-62.56%)
Mutual labels:  monad, functor
rocket-pipes
Powerful pipes for TypeScript, that chain Promise and ADT for you 🚌 -> ⛰️ -> 🚠 -> 🏂 -> 🚀
Stars: ✭ 18 (-98.8%)
Mutual labels:  composition, adt
Lambda
Functional patterns for Java
Stars: ✭ 737 (-50.9%)
Mutual labels:  monad, functor
Ltupatternfactory
Lambda the ultimate Pattern Factory: FP, Haskell, Typeclassopedia vs Software Design Patterns
Stars: ✭ 735 (-51.03%)
Mutual labels:  monad, functor
Fp Core.rs
A library for functional programming in Rust
Stars: ✭ 772 (-48.57%)
Mutual labels:  monad, functor
UnderstandingLanguageExt
This is a tutorial that aims to demonstrate the practical fundamentals behind using LanguageExt in a fashion though step-by-step tutorials which introduce and then build up on concepts.
Stars: ✭ 73 (-95.14%)
Mutual labels:  composition, monad

Build Status Coverage Status Join the chat at https://gitter.im/crocksjs/crocks NPM version

crocks is a collection of popular Algebraic Data Types (ADTs) that are all the rage in functional programming. You have heard of things like Maybe and Either and heck maybe even IO, that is what these are. The main goal of crocks is to curate and provide not only a common interface between each type (where possible of course), but also provide all of the helper functions needed to hit the ground running.

Table of Contents

Installation

crocks is available from npm and is just a shell command away. All you need to do is run the following to save it as a dependency in your current project folder:

$ npm install crocks -S

Usage

There are many options to use crocks to suit the needs of your, projects. When used on the backend or in an environment where size is not a big concern, the entire lib can be brought in and the various elements can be either be plucked off of or referenced by the namespace.

For those cases where size matters, like in the case of frontend bundle building, the individual entities can be brought in. This will ensure that your finished bundles include only what is needed for your application/program.

For using the latter case, refer to the desired function's documentation to find the path in which it resides.

Entire crocks library (CommonJS)

// namespace entire suite to crocks variable
const crocks = require('crocks')

// pluck anything that does not require name-spacing
const { safe, isNumber } = crocks

// still requires entire object, but removes name-spacing
const { and, liftA2 } = require('crocks')

Entire crocks library (JS Modules)

// namespace entire suite to crocks variable
import crocks from 'crocks'

// still imports entire object, but removes name-spacing
import { and, liftA2 }  from 'crocks'

// pluck anything that does not require name-spacing
const { safe, isNumber } = crocks

Single entities (CommonJS)

// require in each entity directly
const and = require('crocks/logic/and')
const curry = require('crocks/helpers/curry')
const isNumber = require('crocks/predicates/isNumber')
const liftA2 = require('crocks/helpers/liftA2')
const safe = require('crocks/Maybe/safe')

Single entities (JS Modules)

// import in each entity directly
import and from 'crocks/logic/and'
import curry from 'crocks/helpers/curry'
import isNumber from 'crocks/predicates/isNumber'
import liftA2 from 'crocks/helpers/liftA2'
import safe from 'crocks/Maybe/safe'

Example

Documentation references: and, curry, predicates (isNumber), liftA2, safe.

// divide :: Number -> Number -> Number
const divide = x => y =>
  x / y

// safeNumber :: a -> Maybe Number
const safeNumber =
  safe(isNumber)

// notZero :: a -> Maybe Number
const notZero = safe(
  and(isNumber, x => x !== 0)
)

// safeDivide:: a -> a -> Maybe Number
const safeDivide = curry(
  (x, y) => liftA2(divide, safeNumber(x), notZero(y))
)

safeDivide(20)(0)
//=> Nothing

safeDivide(20, 0)
//=> Nothing

safeDivide(20, 5)
//=> Just 4

safeDivide('number', 5)
//=> Nothing

Documentation

What is Included?

There are (8) classifications of "things" included in this library:

  • Crocks: These are the ADTs that this library is centered around. They are all Functor based Data Types that provide different computational contexts for working in a more declarative, functional flow. For the most part, a majority of the other bits in crocks exist to serve these ADTs.

  • Monoids: These helpful ADTs are in a class of their own, not really Functors in their own right (although some can be), they are still very useful in our everyday programming needs. Ever need to sum a list of numbers or mix a mess of objects together? This is were you will find the ADTs you need to do that.

  • Combinators: A collection of functions that are used for working with other functions. These do things like compose (2) functions together, or flip arguments on a function. They typically either take a function, return a function or a bit a both. These are considered the glue that holds the mighty house of crocks together and a valuable aid in writing reusable code.

  • Helper Functions: All other support functions that are either convenient versions of combinators or not even combinators at all cover this group.

  • Logic Functions: A helpful collection of logic based functions. All of these functions work with either predicate functions or instances of Pred and let you combine them in some very interesting ways.

  • Predicate Functions: A helpful collection of predicate functions to get you started.

  • Point-free Functions: Wanna use these ADTs in a way that you never have to reference the actual data being worked on? Well here is where you will find all of these functions to do that. For every algebra available on both the Crocks and Monoids there is a function here.

  • Transformation Functions: All the functions found here are used to transform from one type to another, naturally. These come are handy in situations where you have functions that return one type (like an Either), but are working in a context of another (say Maybe). You would like to compose these, but in doing so will result in a nesting that you will need to account for for the rest of your flow.

Contributors

Thanks goes to these wonderful people (emoji key):


Ian Hofmann-Hicks

💻 📖 📹

Ryan

💻 🐛 👀

Andrew Van Slaars

📖 📹

Henrique Limas

💻 📖 👀

Robert Pearce

🐛 💻 👀 📖

Scott McCormack

🐛

Fred Daoud

👀

Karthik Iyengar

👀 💻 📖

Jon Whelan

🐛 💻

Benny Powers

📖 💻 👀

Dale Francis

💻 👀

Premith

📖

Dipen Bagia

💡

Andrew Jones

📖

W. K. Seymour III

📖

Eliseu Benedito Codinhoto

📖

NiallArkEnergy

💻 📖

vidyu

📖

Michael Wolfenden

📖

Johan Codinha

🐛

Matt Ross

💻

Jasmina Jacquelina

📖 💻

Denis Zolkin

📖

Zhentian Wan

📖

RichardForrester

💻 📖 ⚠️

Furkan Tunalı

📖 💡

Paul Desmond Parker

📖

Rodrigo Erades

📖

Jamie Dixon

💻

Basant Pandey

📖

Course/Videos

Video evilsoft

Video avanslaars

Tutorials

Tutorial rpearce

Examples

Example dbagia

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].