Git Product home page Git Product logo

fp's Introduction

https://img.shields.io/npm/v/@keepzen/fp.svg https://img.shields.io/npm/dm/@keepzen/fp.svg https://img.shields.io/npm/dt/@keepzen/fp.svg

id: (any)=>any

The idempotent function.

Parameters

  • v any

Returns any the parameter v.

unary: (fun)=>Function

Convert fun to an unary function.

Parameters

  • fun

Returns Function

binding: (fun,...args)=>Function

Biding function fun with arguments fellow it.

Parameters

  • fun Function This is the function whos parameters you want to bind.
  • args …*any* The values you bind to the parameters of fun.

Return Function.

The length of return function is fun.length - args.length, if args are all normal values, when args includes placeholder _, the length will add the count of placeholders.

Examples

bindidng.placeHolder: Symbol

The place holder that can be use zero or manny times as element of args in binding(fun,...args).

compose: (...funs)=>Function

Compose functions fns to make a new function.

<div>f &compfn; g = f(g(x))</div> Read as “f of g” or “f after g”. Means f after g to run, or f is function of value of g.

Parameters

  • fns Function The functions you want to compose them to be one.

Returns Function

Examples

pipe: (...funs)=>Function

pipe is like the compose but reverse the execute order. It is differtne with pipable. pipable make a functor.

Parameters

  • fns …Function

Returns Function

Examples

m2f: (method)=>Function

Convert a method to a function.

If you have a function fn you can attch it to a object obj like obj.fn=fn, so the this in fn now is obj.

But how do you do if you want use a method as a function? Like sort arrays with a fixed way?

m2f is use to help you for this.

Parameters

  • method Function The method you want covert to a function.

Returns Function.

The return function do same as md, but add this as the first parameter.

Examples

deepCopy: (any[,{freeze}])=>any

Deep copy the value.

Parameters

  • v any
  • $1 Object (optional, default {})
    • $1.freeze (optional, default false)

Returns a new deep Copyed Object.

Examples

constant: (any)=>()=>any

Give a value, get a function, which always return freezen deep copy of the given value.

If you just want get a immutable copy, just use deepCopy(value,{freeze:true}).

Parameters

  • value any

Returns Function : ()=>freezenDeepCopyOfValue

Pipable

Note:This is the package of @keepzen/pipe.js, and in package of @keepzen/fp rexport as Pipable. So the snippets in this section, Pipe, pipe, from, and - are all in namespace of Pipable.

not: not(fn)=>Function

Negative fun.

If fun is a predicater, return a new negative predicater. If fun is a compare function, return the negative compare function.

Parameters

  • fun Function :~(v,…args)=>Boolean|Number~

Returns Function other_fun: (v,...args)=>Boolean|Number

Examples

selectWith: predicate=>array=>Array

select some array with predicate.

Support there is an array include value v, and predicate(v) is true, then select(array) will include v.

Parameters

  • predicate Function (v,index)=>Boolean;

Returns Function select: (array)=>array

Examples

rejectWith: predicate=>array=>Array

Reject some array with predicate.

Support there is an array include value v,and predicate(v) is true, then reject(array) will **not** include v.

Parameters

  • predicate Function : (v,index)=>Boolean;

Returns Function reject:(array)=>array

orderWith: ~(compare[,{asc}])=>array=>Array

Order a array with a compare function. When asc is true, sort value in ascending order else in descending.

For compare(a,b), in asc order, if you want a in front of b, return a negative number; if your want b in front of a return a positive number; else you do not care which first return zero.

Parameters

  • compare Function :~(a,b)=>Boolean~ (optional, default (a,b)=>a-b)
  • $1 Object (optional, default {})
    • $1.asc (optional, default true)

Returns Function order:(array)=>array

Examples

reverse: (array)=>Array

Get a reversed new the array from array.

Parameters

Returns Array

Examples

zip: (aIterable,arrayLikly)=>Array<Array(2)>

Zip arrays a1 and a2 to an array of array.

Parameters

Returns Array Array&lt;Array(2)>

Examples

every: (fun,iterable)=>boolean

Check is every element in iteratble satisfy contiontion fun.

If iterable is empty, return true. See more at [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every*Description);

Parameters

  • fun Function :~(element[,index,array])~
  • iterable **Iterable**

Returns **any** boolean

Examples

all: (fun,iterable)=>boolean

Check is all element in iteratble satisfy contiontion fun.

This is similarity as [every](#every) but if iterable is empty, return false.

Parameters

  • fun Function : (element[,index,array])=>boolean
  • iteratable **Iterable**

Examples

every: (fun,iterable)=>boolean

Similarity as =all=, but if iterable is empty, return true.

any: (fun,iterable)=>boolean

Check is some element in iterable satisfy contiontion fun.

Parameters

  • fun Function : (element[,index,array])=>boolean
  • iterable **Iterable**

Examples

some: (fun,iterable)=>boaolean

Alias of =any=.

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.