Skip to content

Commit

Permalink
binary
Browse files Browse the repository at this point in the history
  • Loading branch information
Deyan Totev committed Jul 19, 2023
1 parent 87a1455 commit 9964790
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 39 deletions.
2 changes: 1 addition & 1 deletion files/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5474,7 +5474,7 @@ Notes:
*/
// @SINGLE_MARKER
export function binary<T>(x: T): T;
export function binary<T extends (...arg: any[]) => any>(fn: T): (...args: any[]) => ReturnType<T>;

/*
Method: call
Expand Down
6 changes: 3 additions & 3 deletions rambda.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/// <reference types="./index.d.ts" />
export * from './src/F.js'
export * from './src/T.js'
export * from './src/add.js'
export * from './src/addIndex.js'
export * from './src/addIndexRight.js'
Expand Down Expand Up @@ -52,6 +50,7 @@ export * from './src/endsWith.js'
export * from './src/eqProps.js'
export * from './src/equals.js'
export * from './src/evolve.js'
export * from './src/F.js'
export * from './src/filter.js'
export * from './src/find.js'
export * from './src/findIndex.js'
Expand Down Expand Up @@ -137,8 +136,8 @@ export * from './src/prop.js'
export * from './src/propEq.js'
export * from './src/propIs.js'
export * from './src/propOr.js'
export * from './src/propSatisfies.js'
export * from './src/props.js'
export * from './src/propSatisfies.js'
export * from './src/range.js'
export * from './src/reduce.js'
export * from './src/reject.js'
Expand All @@ -157,6 +156,7 @@ export * from './src/startsWith.js'
export * from './src/subtract.js'
export * from './src/sum.js'
export * from './src/symmetricDifference.js'
export * from './src/T.js'
export * from './src/tail.js'
export * from './src/take.js'
export * from './src/takeLast.js'
Expand Down
14 changes: 14 additions & 0 deletions source/binary-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {binary} from 'rambda'

describe('R.binary', () => {
it('happy', () => {
const result = binary(function(x: number, y: number, z) {
expect(arguments.length).toBe(2)
expect(z).toBeUndefined()
expect(x).toBe(10)
expect(y).toBe(20)
return x + y
})(10, 20, 30)
result // $ExpectType number
})
})
10 changes: 4 additions & 6 deletions source/binary.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export function binary(foo, bar) {
if (arguments.length === 1){
return (_bar) => binary(foo, _bar);
}
export function binary(fn){
if (fn.length <= 2) return fn

return
}
return (a, b) => fn(a, b)
}
43 changes: 14 additions & 29 deletions source/binary.spec.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
import { binary } from './binary'
import { binary as binaryRamda } from 'ramda'
import { binary } from './binary.js'

test('happy', () => {
const result = binary()
console.log(result)
})

/*
var R = require('../source/index.js');
var eq = require('./shared/eq.js');
describe('binary', function() {
it('turns multiple-argument function into binary one', function() {
R.binary(function(x, y, z) {
eq(arguments.length, 2);
eq(typeof z, 'undefined');
})(10, 20, 30);
});
const result = binary(function (
x, y, z
){
expect(arguments).toHaveLength(2)
expect(z).toBeUndefined()
expect(x).toBe(10)
expect(y).toBe(20)

it('initial arguments are passed through normally', function() {
R.binary(function(x, y, z) {
eq(x, 10);
eq(y, 20);
void z;
})(10, 20, 30);
});
});
*/
return x + y
})(
10, 20, 30
)
expect(result).toBe(30)
})

0 comments on commit 9964790

Please sign in to comment.