Created
March 28, 2021 14:49
-
-
Save friendlyanon/a6163a59c8a7840727492ae07a917964 to your computer and use it in GitHub Desktop.
This file contains 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
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