Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/code boilerplate #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ coverage
*.lcov
*.log
*~
.idea
2 changes: 1 addition & 1 deletion source/base/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* multiply(10)(10); // => 100
*/
export const partial = (f, ...as) => {
if (as.length === 0) { return f.call(); }
if (!as.length) { return f.call(); }
const a = as.shift();
if (a === undefined) { return f; }
const p = f.bind(f, a);
Expand Down
4 changes: 2 additions & 2 deletions source/list/building.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {error} from '../error';
*/
export const scanl = (f, q, ls) => {
const scanl_ = (f, q, ls) => {
if (isList(ls) === false) { return error.listError(ls, scanl); }
if (!isList(ls)) { return error.listError(ls, scanl); }
if (isEmpty(ls)) { return cons(q)(emptyList); }
const x = head(ls);
const xs = tail(ls);
Expand All @@ -63,7 +63,7 @@ export const scanl = (f, q, ls) => {
*/
export const scanr = (f, q0, as) => {
const scanr_ = (f, q0, as) => {
if (isList(as) === false) { return error.listError(as, scanr); }
if (!isList(as)) { return error.listError(as, scanr); }
if (isEmpty(as)) { return list(q0); }
const x = head(as);
const xs = tail(as);
Expand Down
6 changes: 3 additions & 3 deletions source/list/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ export const listFilter = (start, end, filt) => {
*/
export const listAppend = (xs, ys) => {
const listAppend_ = (xs, ys) => {
if (isList(xs) === false ) { return error.listError(xs, listAppend); }
if (isList(ys) === false ) { return error.listError(ys, listAppend); }
if (!isList(xs)) { return error.listError(xs, listAppend); }
if (!isList(ys)) { return error.listError(ys, listAppend); }
if (isEmpty(xs)) { return ys; }
if (isEmpty(ys)) { return xs; }
if (type(head(xs)) === type(head(ys))) { return cons(head(xs))(listAppend(tail(xs))(ys)); }
Expand Down Expand Up @@ -317,7 +317,7 @@ export const length = xs => {
* @returns {boolean} `true` if the object is a `List` and `false` otherwise
* @kind function
*/
export const isList = a => a instanceof List ? true : false;
export const isList = a => a instanceof List;

/**
* Check whether a `List` is empty. Returns `true` if the `List` is empty or false if it is
Expand Down
6 changes: 3 additions & 3 deletions source/list/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ export class List extends Type {
}
// Ord
static compare(as, bs) {
if (isEmpty(as) && isEmpty(bs)) { return EQ; }
if (isEmpty(as) && isEmpty(bs) === false) { return LT; }
if (isEmpty(as) === false && isEmpty(bs)) { return GT; }
if (isEmpty(as) && isEmpty(bs)) return EQ;
if (isEmpty(as) && !isEmpty(bs)) return LT;
if (!isEmpty(as) && isEmpty(bs)) return GT;
if (compare(head(as), head(bs)) === EQ) { return compare(tail(as), tail(bs)); }
return compare(head(as), head(bs));
}
Expand Down
8 changes: 4 additions & 4 deletions source/maybe/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const Nothing = new Maybe();
* @returns {Maybe} `Just a` or `Nothing`
* @kind function
*/
export const just = a => a === undefined || a === null || a !== a ? Nothing : new Maybe(a);
export const just = a => a == undefined || a !== a ? Nothing : new Maybe(a);

/**
* Take a default value, a function, and a `Maybe` value. If the `Maybe` value is `Nothing`, return
Expand Down Expand Up @@ -76,7 +76,7 @@ export const maybe = (n, f, m) => {
* @returns {boolean} `true` if the object is a `Maybe` and `false` otherwise
* @kind function
*/
export const isMaybe = a => a instanceof Maybe ? true : false;
export const isMaybe = a => a instanceof Maybe;

/**
* Determine whether an object is a `Just`.
Expand All @@ -87,7 +87,7 @@ export const isMaybe = a => a instanceof Maybe ? true : false;
*/
export const isJust = m => {
if (isMaybe(m) === false) { return error.typeError(m, isJust); }
return isNothing(m) ? false : true;
return !isNothing(m);
}

/**
Expand All @@ -99,7 +99,7 @@ export const isJust = m => {
*/
export const isNothing = m => {
if (isMaybe(m) === false) { return error.typeError(m, isNothing); }
return m === Nothing ? true : false;
return m === Nothing;
}

/**
Expand Down
7 changes: 3 additions & 4 deletions source/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ export const typeCheck = (a, b) => {
if (a instanceof Type && b instanceof Type) {
return dataType(a).type(a) === dataType(b).type(b);
}
if (dataType(a) === dataType(b)) { return true; }
return false;
}
return dataType(a) === dataType(b);
};
return partial(typeCheck_, a, b);
}
};