Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
Add functions for helper functions
Browse files Browse the repository at this point in the history
- Move `identity`, our only current helper function
- Add noop function
  - Can take any number of arguments, or expect any type as output.
  • Loading branch information
epelz committed Aug 11, 2015
1 parent de176e8 commit bec3556
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 22 deletions.
17 changes: 17 additions & 0 deletions src/functions.ts
@@ -0,0 +1,17 @@
/**
* Returns the same value
* @param value
* @returns {T}
*/
export function identity<T>(value: T): T {
return value;
}

/**
* A type- and argument-agnostic function that returns null.
* @param args
* @returns {any}
*/
export function noop(...args: any[]): any {
return null;
}
10 changes: 0 additions & 10 deletions src/identity.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/index.ts
Expand Up @@ -3,8 +3,8 @@
*/
export import collections = require("./collections");
export import Either = require("./either");
export import functions = require("./functions");
export import Handle = require("./handle");
export import identity = require("./identity");
export import lists = require("./lists");
export import Map = require("./map");
export import Optional = require("./optional");
Expand Down
29 changes: 29 additions & 0 deletions test/functions_test.ts
@@ -0,0 +1,29 @@
import chai = require("chai");
import tsutil = require("../src/index");

var functions = tsutil.functions;
var assert = chai.assert;

suite("functions", () => {
suite("identity", () => {
test("should return the same value", () => {
var value = {};
assert.equal(value, functions.identity(value));
});
});

suite("noop", () => {
test("can be called with no arguments", () => {
assert.isNull(functions.noop());
});

test("can be called with two arguments", () => {
assert.isNull(functions.noop({}, {}));
});

test("can be called for any expected return type", () => {
var result: { fake_type: number } = functions.noop();
assert.isNull(result);
});
});
});
11 changes: 0 additions & 11 deletions test/identity_test.ts

This file was deleted.

0 comments on commit bec3556

Please sign in to comment.