Skip to content

Instantly share code, notes, and snippets.

@zaetrik
Created May 2, 2020 16:50
Show Gist options
  • Save zaetrik/bd4f378230457170f49a394e84e50f82 to your computer and use it in GitHub Desktop.
Save zaetrik/bd4f378230457170f49a394e84e50f82 to your computer and use it in GitHub Desktop.
Eq Type Class Extenden
type Album = {
artist: Artist;
title: string;
albumId: number;
};
const eqAlbumBySameArtist: Eq<Album> = contramap((album: Album) => album.artist)(eqArtist);
// Now we can check if an album is made by the same artist
eqAlbumBySameArtist.equals(
{ artist: { artistId: 1, name: "EDEN" }, title: "no future", albumId: 1 },
{ artist: { artistId: 1, name: "eden" }, title: "vertigo", albumId: 5 }
) // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment