Closed mfirry closed 5 years ago
It needs an instance of Eq
I guess, like clamp needs an instance of Ord
import { getEq } from 'fp-ts/lib/Array';
import { Eq } from 'fp-ts/lib/Eq';
import { takeLast } from './takeLast';
function _endsWith<A>(E: Eq<A>): (suffix: Array<A>, as: Array<A>) => boolean {
const eqArray = getEq(E);
return (suffix, as) => eqArray.equals(suffix, takeLast(suffix.length, as));
}
export function endsWith<A>(
E: Eq<A>
): {
(suffix: Array<A>): (as: Array<A>) => boolean;
(suffix: Array<A>, as: Array<A>): boolean;
};
export function endsWith<A>(E: Eq<A>): (suffix: Array<A>, oas?: Array<A>) => any {
const _endsWithE = _endsWith(E);
return (suffix, oas) => {
if (oas === undefined) {
return (as: Array<A>) => _endsWithE(suffix, as);
} else {
return _endsWithE(suffix, oas);
}
};
}
Super cool. Right now I'm fighting with this https://gist.github.com/mfirry/3065083ca0891ebd74f7ce75df10ad34 but I'll continue with this. Grazie Giulio.
I think you can fix that by running: npm run prettier-write
I'm fighting with this
@mfirry If you work in VSCode, I can also suggest to install the prettier extension and configure "Format on save" so that prettier works transparently.
It needs an instance of Eq I guess, like clamp needs an instance of Ord
Yes, looking at the Ramda signatures, this is sometimes clear, e.g. in the case of clamp
:
Ord a => a → a → a → a
and sometimes less so, like in the case of endsWith
: the Eq
instance in Ramda is never annotated in the docs, but the library always implicitly dispatches to R.equals
internally, which is kind of an Eq<unknown>
instance.
I think you can fix that by running:
npm run prettier-write
Yeah it's just a) me not using prettier right now b) error being cryptic. Thanks for the heads up.
I've tried a simple definition along these lines:
(also lurking on https://github.com/ramda/ramda/blob/v0.26.1/source/endsWith.js#L27) But it doesn't seem to work. Any hint?