How to use Pattern type in Motoko Text (base library)

The Motoko base library for Text reads:

  /// A pattern `p` describes a sequence of characters. A pattern has one of the following forms:
  ///
  /// * `#char c` matches the single character sequence, `c`.
  /// * `#predicate p` matches any single character sequence `c` satisfying predicate `p(c)`.
  /// * `#text t` matches multi-character text sequence `t`.
  ///
  /// A _match_ for `p` is any sequence of characters matching the pattern `p`.

 public type Pattern = { #char : Char; #text : Text; #predicate : (Char -> Bool) };

However, If I try something like:

if(Text.startsWith(my_text, '0') == true){
  Debug.print("foo");
}; 

I get the error:

expression of type
  Char
cannot produce expected type
  {#char : Char; #predicate : Char -> Bool; #text : Text/2}

So my question is: How can I use the Pattern type to invoke functions such as Text.startsWith?

Thanks in advance

Solved the issue. The correct syntax should be:

if(Text.startsWith(my_text, #char '0') == true){
  Debug.print("foo");
}; 
2 Likes

Thank you. I think there would have thousands of years of life saving if there was some examples in this documentation…