src/FunctionalProgramming.jl

changeset 37
f8be66557e0f
parent 33
a60d2f12ef93
--- a/src/FunctionalProgramming.jl	Wed Dec 15 01:09:09 2021 +0200
+++ b/src/FunctionalProgramming.jl	Wed Dec 22 11:13:38 2021 +0200
@@ -17,7 +17,8 @@
 ##############
 
 export curry,
-       curryflip
+       curryflip,
+       maybe
 
 ###########
 # Currying
@@ -57,4 +58,12 @@
     return x ->f(x, y...; kwargs...)
 end
 
+"""
+`maybe(f, x)`
+
+Returns `nothing` if `x` is `nothing, otherwise `f(x)`.
+"""
+maybe( :: Function, :: Nothing) = nothing
+maybe(f :: Function, x :: T) where T = f(x)
+
 end # module

mercurial