Intro

Since my contract has ended, I have been using my unemployment to dig deeper into F#. Finally, it’s beginning to click for me. Now as I reason with my code, I recognize opportunities for some open source utilities.

As a result of my observation, I decided to contribute an active pattern library to NuGet. It’s Bizmonger.ActivePatterns.

module ValuesAP

let (|Equal|Different|) = function
    | v1, v2 when v1 = v2 -> Equal
    | _                   -> Different

module ListsAP

let (|None|One|Many|) (x:'a list) =
    match x with
    | x when x.Length > 1 -> Many
    | x when x.Length = 1 -> One
    | _                   -> None

module NumbersAP

let (|Positive|Neutral|Negative|) = function
    | x when x > 0 -> Positive
    | x when x < 0 -> Negative
    | _            -> Neutral

Here’s a sample of how to use the NumbersAP active pattern

let result = match -5 with
             | Positive -> "is positive"
             | Negative -> "is negative"
             | Neutral  -> "is neutral"

I think adding “AP” as a suffix to module names may be the way to go. Hence, this convention is used with JavaScript libraries. Thus, I plan on adding more active patterns to this package as I continue to build solutions.

Conclusion

In conclusion, since my contract has ended, I have been using my unemployment to dig deeper into F#. Finally, it’s beginning to click for me. Now as I reason with my code, I recognize opportunities for some open source utilities.

As a result of my observation, I decided to contribute an active pattern library to NuGet. It’s Bizmonger.ActivePatterns.

Advertisements