Giter Site home page Giter Site logo

eckelon / convenient-fp-utils Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 8 KB

module that wraps different fp libraries together and adds some convenient functions

Home Page: https://github.com/eckelon/convenient-fp-utils

JavaScript 100.00%
sanctuary javascript functional-programming module library

convenient-fp-utils's Introduction

convenient-fp-utils 1.0.0

module that wraps different fp libraries together and adds some convenient functions

src/index.js

module.exports()

Convenient FP Utils is a module that wraps different fp libraries together.

Why not ramda or lodash/fp?

I like ramda and lodash/fp; they're cool in most situations, but despite they help us to write clean and composable code, this code is not type-safe. Sanctuary allows us to write type-safe code with its functions, and with sanctuary-def we're able to write type-safe functions.

Returns
  • object all the convenient-fp-utils utilities

src/utils.js

module.exports(dependencies)

This object offers a curated set of composable functions that we usually use.

Parameters
Name Type Description
dependencies object object containing the sanctuary (S) dependency.  
Returns
  • object utils functions.

tap()

tap :: (a -> Any) -> a -> a

Runs the given function with the supplied object, then returns the object.

Returns
  • Any returns what the function passed returns.

noop()

This is the 'no operation' function. It just returns undefined.

Returns
  • Undefined

T()

T :: Boolean b => a -> b

Always returns true

Returns
  • Boolean

F()

F :: Boolean b => a -> b

Always returns false

Returns
  • Boolean

zipObj()

zipObj :: Array -> Array -> Object

Creates a new object out of a list of keys and a list of values. Key/value pairing is truncated to the length of the shorter of the two lists.

zipObj(['a', 'b', 'c'])([1, 2, 3]); //=> {a: 1, b: 2, c: 3}
Returns
  • Object

pResolve()

pResolve :: a -> Promise

It returns a promise that resolves with the given param

Returns
  • Promise

pReject()

pReject :: a -> Promise

It returns a promise that rejects with the given param

Returns
  • Promise

map2()

map2 :: Functor f => (a -> b) -> f a -> f b

Takes a function and a functor with another functor inside, applies the function to each of the deepest functor's values, and returns a functor of the same shape than the top functor.

Returns
  • Functor

map3()

map2 :: Functor f => (a -> b) -> f a -> f b

Takes a function and a functor with two nested functors inside, applies the function to each of the deepest functor's values, and returns a functor of the same shape than the top functor.

Returns
  • Functor

allPass()

allPass :: Any a => Boolean b => [(a -> b)] -> (a -> b)

Takes a list of predicates and returns a predicate that returns true for a given list of arguments if every one of the provided predicates is satisfied by those arguments. False otherwise.

Returns
  • Boolean

anyPass()

anyPass :: Any a => Boolean b => [(a -> b)] -> (a -> b)

Takes a list of predicates and returns a predicate that returns true for a given list of arguments if at least one of the provided predicates is satisfied by those arguments. False otherwise.

Returns
  • Boolean

parallelAp()

parallelAp :: Function f => Function g => Any a => Array(a)

Takes two functions and applies them to the same given value, returning an array of results

Returns
  • Array

includes()

includes :: Any => Array Any => Boolean

Takes a value and an array and returns True if the value is contained in the array. False otherwise.

Returns
  • Boolean

getEq()

getEq :: Function => String => Any => Object => Maybe Boolean

Returns true if the specified object property is equal, in S.equals terms, to the given value; false otherwise.

Returns
  • Boolean

findEq()

findEq :: Function Boolean => String => Any => Array Object => Maybe Boolean

Takes a predicate, a field name, a value and an object array and returns Just the leftmost object of the array which field equals the desired value; Nothing otherwise.

Returns
  • Maybe

pluck()

pluck :: Function Boolean => String => Array Maybe Any

Returns a new list by plucking the same named property off all objects in the list supplied.

Returns
  • Array

src/http.js

module.exports(dependencies)

This object offers a curated set of composable functions to make http-requests with fetch API

Parameters
Name Type Description
dependencies object object containing the fluture and sanctuary (S) dependencies.  
Returns
  • object http functions.

doGet()

doGet :: Promise b => a -> b

It makes a GET http request and returns a promise result

Returns
  • Promise

doPost()

doPost :: Promise c => a -> b -> c

It makes a POST http request with data as body, and returns a promise result

Returns
  • Promise

Documentation generated with doxdox.

convenient-fp-utils's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.