Created
May 2, 2020 16:50
-
-
Save zaetrik/bd4f378230457170f49a394e84e50f82 to your computer and use it in GitHub Desktop.
Eq Type Class Extenden
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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