Skip to content

Instantly share code, notes, and snippets.

@bennage
Created July 13, 2010 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bennage/474213 to your computer and use it in GitHub Desktop.
Save bennage/474213 to your computer and use it in GitHub Desktop.
// what's a better way?
let fullName (first,last) =
match (first, last) with
"",_ | null,_ -> first
| _,null | _,"" -> last
| _ -> sprintf "%s.%s" first last
@bennage
Copy link
Author

bennage commented Jul 13, 2010

the logic is

  • if first is null or empty just return last
  • if last is null or empty just return first
  • if neither are null/empty then concatenate with using a certain formatting

@randomcodenz
Copy link

           let isnullorempty = function
             | null -> true
             | "" -> true
             | _ -> false

           let fullname(first,last) =
             match isnullorempty first with
             | true -> last
             | false -> match isnullorempty last with
                           | true -> first
                           | false -> sprintf "%s.%s" first last

@bennage
Copy link
Author

bennage commented Jul 13, 2010

Matt offered this solution too:
http://gist.github.com/474421

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment