Skip to content

Commit c33420d

Browse files
Adding missing find function, fixes #564
find is referenced in chapter 8 and is needed for the IO example: // findParam :: String -> IO Maybe [String] const findParam = key => map(compose(Maybe.of, find(compose(eq(key), head)), params), url);
1 parent aff5bfd commit c33420d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

exercises/support.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ class Task {
559559
}
560560
}
561561

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

727+
const find = curry(function find(fn, xs) {
728+
assert(
729+
typeof fn === 'function' && Array.isArray(xs),
730+
typeMismatch('(a -> Boolean) -> [a] -> a', [getType(fn), getType(xs), getType(xs)].join(' -> '), 'find'),
731+
);
732+
733+
return xs.find(fn);
734+
});
735+
727736
const flip = curry(function flip(fn, a, b) {
728737
assert(
729738
typeof fn === 'function',
@@ -1071,6 +1080,7 @@ if (typeof module === 'object') {
10711080
concat,
10721081
eq,
10731082
filter,
1083+
find,
10741084
flip,
10751085
forEach,
10761086
head,

0 commit comments

Comments
 (0)