Skip to content

Commit

Permalink
refer to replace and toLowerCase functions in the appendix fro ch05. Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KtorZ committed Jan 29, 2018
1 parent 991a040 commit 2ae25c4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
* [Appendix C: Pointfree Utilities](appendix_c.md)
* [chain](appendix_c.md#chain)
* [concat](appendix_c.md#concat)
* [eq](appendix_c.md#eq)
* [filter](appendix_c.md#filter)
* [flip](appendix_c.md#flip)
* [forEach](appendix_c.md#foreach)
Expand All @@ -122,5 +123,7 @@
* [sortBy](appendix_c.md#sortby)
* [split](appendix_c.md#split)
* [take](appendix_c.md#take)
* [toLowerCase](appendix_c.md#tolowercase)
* [toUpperCase](appendix_c.md#touppercase)
* [traverse](appendix_c.md#traverse)
* [unsafePerformIO](appendix_c.md#unsafeperformio)
21 changes: 21 additions & 0 deletions appendix_c.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ const chain = curry((fn, m) => m.chain(fn));
const concat = curry((a, b) => a.concat(b));
```

## eq

```js
// eq :: Eq a => a -> a -> Boolean
const eq = curry((a, b) => a === b);
```

## filter

```js
Expand Down Expand Up @@ -165,6 +172,20 @@ const split = curry((sep, str) => str.split(sep));
const take = curry((n, xs) => xs.slice(0, n));
```

## toLowerCase

```js
// toLowerCase :: String -> String
const toLowerCase = s => s.toLowerCase();
```

## toUpperCase

```js
// toUpperCase :: String -> String
const toUpperCase = s => s.toUpperCase();
```

## traverse

```js
Expand Down
3 changes: 3 additions & 0 deletions ch05.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ There's no right or wrong answers - we're just plugging our legos together in wh

Pointfree style means never having to say your data. Excuse me. It means functions that never mention the data upon which they operate. First class functions, currying, and composition all play well together to create this style.

> Hint: Pointfree versions of `replace` & `toLowerCase` are defined in the [Appendix C -
> Pointfree Utilities](./appendix_c.md). Do not hesitate to have a peek!
```js
// not pointfree because we mention the data: word
const snakeCase = word => word.toLowerCase().replace(/\s+/ig, '_');
Expand Down
20 changes: 20 additions & 0 deletions exercises/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,24 @@ const take = curry(function take(n, xs) {
return xs.slice(0, n);
});

const toLowerCase = function toLowerCase(s) {
assert(
typeof s === 'string',
typeMismatch('String -> String', [getType(s), '?'].join(' -> '), 'toLowerCase'),
);

return s.toLowerCase();
};

const toUpperCase = function toUpperCase(s) {
assert(
typeof s === 'string',
typeMismatch('String -> String', [getType(s), '?'].join(' -> '), 'toLowerCase'),
);

return s.toUpperCase();
};


/* ---------- Chapter 4 ---------- */

Expand Down Expand Up @@ -1036,6 +1054,8 @@ if (typeof module === 'object') {
sortBy,
split,
take,
toLowerCase,
toUpperCase,

// Chapter 04
keepHighest,
Expand Down

0 comments on commit 2ae25c4

Please sign in to comment.