Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Curry All Code

NotificationsYou must be signed in to change notification settings

Debdut/omg-curry

Repository files navigation

Generic badgeGeneric badge

TwitterTwitter

Feature Complete Curry Library

Logo

Features

  • Fixed Functions ⟶ Curry
  • Operators ⟶ Curry
  • Curry ⟶ Fixed Functions
  • Infinite Currying
  • Lazy Curry

Installation

npm install omg-curry

Usage

constcurry=require('omg-curry')

Fixed Functions

Convert a function into curry

functionmap(fn,default,list){}constmapK=curry.fixed(map)constsquare=a=>a**2mapK(square)(0)([1,2,3,4,null])// [1, 4, 9, 16, 0]// or reuseconstmapSquare=mapK(square)(0)mapSquare([1,2,3,4,null])// [1, 4, 9, 16, 0]

Operators

Create N-length Curry from an operator

constadd=(a,b)=>a+bconstadd4=curry.op(add,4)add4(1)(3)(5)(10)add4(1)(3,5)(10)add4(1,3,5,10)// 19constaddInfty=curry.op(add,Infinity)// () to endaddInfty(1)(1)(1,1)(1)(1)()// 6constadd4Lazy=curry.op(add,4,true)// same as add4 buts evaluates at the end
constaltSum=(a,b,i)=>a+(-1)**i*bconstaltSum5=curry.op(altSum,5)// (a, b, c, d, e) => a - b + c - d + ealtSum5(1)(2)(3)(4,5)// 1 - 2 + 3 - 4 + 5// 3

DeCurry

Convert Curry to Fixed Functions

constadd4Fixed=curry.deCurry(add4Curry)

WTF is Curry?

A Curry takes arguments one by one unlike functions which take all arguments at once.

// Functionadd(1,2,3)// 6// Curryadd(1)(2)(3)// 6

Support

  • Browser
  • Node

[8]ページ先頭

©2009-2025 Movatter.jp