1 people like it.

Active pattern example

Example active pattern for tweet.

Active pattern

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
/// Checks to see if a list has exactly one element
/// and checks to see if that one element is a
/// particular given element.
let (|Singleton|_|) element listarg =
  match listarg with
  | [x]
    -> if x = element
        then Some ()
        else None
  | _ -> None
val element : 'a (requires equality)
val listarg : 'a list (requires equality)
val x : 'a (requires equality)
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
Raw view Test code New version

More information

Link:http://fssnip.net/lE
Posted:10 years ago
Author:Robert Nielsen
Tags: active pattern , twitter , example