Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// what's a better way?
let fullName (first,last) =
match (first, last) with
"",_ | null,_ -> first
| _,null | _,"" -> last
| _ -> sprintf "%s.%s" first last
@bennage

This comment has been minimized.

Copy link
Owner 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

This comment has been minimized.

Copy link

randomcodenz commented Jul 13, 2010

           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

This comment has been minimized.

Copy link
Owner 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
You can’t perform that action at this time.