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

Adding missing find function, fixes #564 #595

Open
wants to merge 3 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 SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
* [concat](appendix_c.md#concat)
* [eq](appendix_c.md#eq)
* [filter](appendix_c.md#filter)
* [find](appendix_c.md#find)
* [flip](appendix_c.md#flip)
* [forEach](appendix_c.md#foreach)
* [head](appendix_c.md#head)
Expand Down
13 changes: 10 additions & 3 deletions appendix_c.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ In order to find functions that are more production-ready, have a peek at

Note that functions refer to the `curry` & `compose` functions defined in [Appendix A](./appendix_a.md)

## add
## add

```js
// add :: Number -> Number -> Number
Expand Down Expand Up @@ -52,14 +52,21 @@ const eq = curry((a, b) => a === b);
const filter = curry((fn, xs) => xs.filter(fn));
```

## find

```js
// find :: (a -> Boolean) -> [a] -> a
const find = curry((fn, list) => list.find(fn))
```

## flip

```js
// flip :: (a -> b -> c) -> b -> a -> c
const flip = curry((fn, a, b) => fn(b, a));
```

## forEach
## forEach

```js
// forEach :: (a -> ()) -> [a] -> ()
Expand Down Expand Up @@ -108,7 +115,7 @@ const map = curry((fn, f) => f.map(fn));
const match = curry((re, str) => re.test(str));
```

## prop
## prop

```js
// prop :: String -> Object -> a
Expand Down
12 changes: 11 additions & 1 deletion exercises/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ class Task {
}
}

// In nodejs the existance of a class method named `inspect` will trigger a deprecation warning
// In nodejs the existence of a class method named `inspect` will trigger a deprecation warning
// when passing an instance to `console.log`:
// `(node:3845) [DEP0079] DeprecationWarning: Custom inspection function on Objects via .inspect() is deprecated`
// The solution is to alias the existing inspect method with the special inspect symbol exported by node
Expand Down Expand Up @@ -724,6 +724,15 @@ const filter = curry(function filter(fn, xs) {
return xs.filter(fn);
});

const find = curry(function find(fn, xs) {
assert(
typeof fn === 'function' && Array.isArray(xs),
typeMismatch('(a -> Boolean) -> [a] -> a', [getType(fn), getType(xs), getType(xs)].join(' -> '), 'find'),
);

return xs.find(fn);
});

const flip = curry(function flip(fn, a, b) {
assert(
typeof fn === 'function',
Expand Down Expand Up @@ -1071,6 +1080,7 @@ if (typeof module === 'object') {
concat,
eq,
filter,
find,
flip,
forEach,
head,
Expand Down