Skip to content

Instantly share code, notes, and snippets.

@friendlyanon
Created March 28, 2021 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save friendlyanon/a6163a59c8a7840727492ae07a917964 to your computer and use it in GitHub Desktop.
Save friendlyanon/a6163a59c8a7840727492ae07a917964 to your computer and use it in GitHub Desktop.
template<class T, template<class> class M>
[[nodiscard]] constexpr auto
fmap(const M<T>& x, auto&& f)
noexcept(noexcept(M<decltype(f(*x))>{f(*x)}))
-> M<decltype(f(*x))>
{
if (x) {
return {f(*x)};
} else {
return {};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment