Skip to content

Instantly share code, notes, and snippets.

@Willmo36
Created February 5, 2018 16:32
Show Gist options
  • Save Willmo36/ab3865d8746014f86b1191d34c6b4bce to your computer and use it in GitHub Desktop.
Save Willmo36/ab3865d8746014f86b1191d34c6b4bce to your computer and use it in GitHub Desktop.
distinctUntilChange - TypeScript extend Most.js
import { Stream } from "most";
import * as R from "ramda";
declare module "most" {
interface Stream<A> {
distinctUntilChange<T>(seed: T): Stream<T>;
}
}
const pairs = <P, C>(prev: P, current: C) => ({ seed: current, value: [prev, current] });
function distinctUntilChange<T>(stream: Stream<T>, seed: T) {
return stream
.loop<T, T[]>(pairs, seed)
.filter(p => !R.equals(p[0], p[1]))
.map(p => p[1]);
}
Stream.prototype.distinctUntilChange = function<T>(seed: T) {
return distinctUntilChange(this, seed);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment