Carl Nolan’s ramblings on development
In my previous post I talked about some extension methods for string checking:
But what would be a post if there was not a F# equivalent.
Interestingly the ability to perform checks on each character in a string is actually already supported by F#; using the String.forall:
However, one can also easily create the same String extension methods, as in the previous post, in F#:
The extension methods are more explicit in F#, compared to the C# implementation, as one merely extends the appropriate type; in this case String.
One of the main differences between this and the C# implementation is around the use of String.forall method rather than the LINQ IEnumerable<T>.All method. Also, an option parameter is used for the string length specification.
These extensions methods allow one to write statements such as:
The main downside to the F# implementation is that the extension methods can only be consumed from F#.