Skip to content

Commit 84d75a0

Browse files
Deploy docs to GitHub Pages 2085239
1 parent 9b1665f commit 84d75a0

File tree

10 files changed

+83
-83
lines changed

10 files changed

+83
-83
lines changed

articles/async.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ <h2 id="async-match-expressions">Async Match Expressions</h2>
120120
pattern is matched successfully (sync actions are turned into async actions).</p>
121121
<p>Async match expressions can be executed using the <code>ExecuteAsync</code>, <code>ExecuteNonStrictAsync</code> and
122122
<code>ExecuteWithFallthroughAsync</code> methods. The <code>ToFunction</code> method and its variations are also available.
123-
<code>ExecuteWithFallthroughAsync</code> returns an <code>IAsyncEnumerable</code> which enable lazy async execution of match expressions.</p>
123+
<code>ExecuteWithFallthroughAsync</code> returns an <code>IAsyncEnumerable</code> which enables lazy async execution of match expressions.</p>
124124
<p>The <code>Matchmaker.Linq</code> namespace contains the <code>EnumerateAsync</code> extension method for <code>IAsyncEnumerable&lt;T&gt;</code> which
125125
enumerates it and ignores the result. You can use it if you just want to execute the match statement with fall-through.</p>
126126
<p>Static async match expressions are also available. Use the <code>AsyncMatch.CreateStatic</code> methods to create them, just like

articles/expressions.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ <h3 id="creating-match-expressions">Creating Match Expressions</h3>
9595
<p>A match expression can be created using the <code>Create</code> methods of the static class <code>Match</code>.</p>
9696
<h3 id="adding-cases">Adding Cases</h3>
9797
<p>The <code>Match</code> classes include <code>Case</code> methods which are used to add a pattern and a function which is executed if the match
98-
is successful. Match expressions are immutable <code>Case</code> methods return new match expressions; they do not affect the
98+
is successful. Match expressions are immutable <code>Case</code> methods return new match expressions; they do not affect the
9999
ones on which they are called.</p>
100-
<p><code>Case</code> methods are generic they also contain information about the pattern's transformation type. Match expressions
100+
<p><code>Case</code> methods are generic they also contain information about the pattern's transformation type. Match expressions
101101
can contain patterns of arbitrary transformation types without knowing about these types.</p>
102102
<h3 id="executing-match-expressions">Executing Match Expressions</h3>
103103
<p>To execute a match expression, the <code>ExecuteOn</code> method is used. It takes the input value to match. There are two modes of
@@ -108,7 +108,7 @@ <h3 id="executing-match-expressions">Executing Match Expressions</h3>
108108
which executes the match expression in the non-strict mode. It returns <code>MatchResult&lt;TOutput&gt;</code> because the result might
109109
not be present.</p>
110110
<p>In the <code>Match&lt;TInput&gt;</code> class, the <code>ExecuteOn</code> method doesn't return anything, and also throws a <code>MatchException</code> if the
111-
match wasn't successful. This class also contains the <code>ExecuteNonStrict</code> method it returns a boolean value which
111+
match wasn't successful. This class also contains the <code>ExecuteNonStrict</code> method it returns a boolean value which
112112
indicates whether the match was successful and doesn't throw an exception if it wasn't.</p>
113113
<p>The <code>ToFunction</code> method and its variations are also available. They return a function which, when called, will execute
114114
the match expression.</p>
@@ -123,8 +123,8 @@ <h2 id="matching-with-fall-through">Matching with Fall-through</h2>
123123
is enabled for a pattern, then the expression will continue searching for the next successful pattern. If it isn't, then
124124
the expression will stop at this pattern and not go any further.</p>
125125
<p><code>Match.Create</code> is also overloaded to take the default fall-through behavior.</p>
126-
<p>Matching with fall-through is lazy i.e. it returns an <code>IEnumerable</code> and is only executed when this enumerable is
127-
enumerated. Because matching will fall-through is lazy, it doesn't have any modes of execution the user must decide
126+
<p>Matching with fall-through is lazy, i.e., it returns an <code>IEnumerable</code> and is only executed when this enumerable is
127+
enumerated. Because matching will fall-through is lazy, it doesn't have any modes of execution the user must decide
128128
whether to throw an exception or not if there were no successful matches.</p>
129129
<p>In the <code>Match&lt;TInput, TOutput&gt;</code> class, the <code>ExecuteWithFallthrough</code> method returns an <code>IEnumerable&lt;TOutput&gt;</code> which can
130130
be used to get all successful match results.</p>
@@ -178,12 +178,12 @@ <h3 id="the-initialization-problem">The Initialization Problem</h3>
178178
.ExecuteOn(i);
179179
</code></pre>
180180
<p>The problem here is that if we call <code>DoStuff</code> 10,000 times, we will initialize the match expression 10,000 times as
181-
well, even though it's actually the same expression. Having just 4 cases may not seem like much, but the lag does
182-
accumulate if we execute it thousands of times.</p>
181+
well, even though it's actually the same expression. Having just 4 cases may not seem like much, but the lag and
182+
allocations do accumulate if we execute it thousands of times.</p>
183183
<p>We can save the expression in a field and then call the <code>ExecuteOn</code> method on this field. But this makes the code much
184184
less readable because the case definitions are in a different place from the actual execution point.</p>
185185
<h3 id="the-solution">The Solution</h3>
186-
<p>There is a way to create static match expressions expressions which will be initialized only once.</p>
186+
<p>There is a way to create static match expressions expressions which will be initialized only once.</p>
187187
<p>The <code>Match</code> class contains the <code>CreateStatic</code> methods which allow the creation of static match expressions. Take a look
188188
at the modified example:</p>
189189
<pre><code class="lang-c#">void DoStuff(int i) =&gt;
@@ -199,7 +199,7 @@ <h3 id="the-solution">The Solution</h3>
199199
only once, and its initialization code is in the same place as its execution point.</p>
200200
<p>The parameter of the build action has the type <code>MatchBuilder&lt;TInput, TOutput</code> or <code>MatchBuilder&lt;TInput&gt;</code>, depending on
201201
which type of match expressions you are building. This type has the same methods for adding cases as the <code>Match</code> classes
202-
and is mutable the methods return the same builder instance.</p>
202+
and is mutable the methods return the same builder instance.</p>
203203
<p><code>MatchBuilder</code> also has the <code>Fallthrough</code> method which specifies the default fall-through behavior. But this method
204204
specifies fall-through behavior only for cases that are defined after it. For example:</p>
205205
<pre><code class="lang-c#">builder

articles/migration.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ <h1 id="migration-guide">Migration Guide</h1>
9191
<a href="https://github.com/TolikPylypchuk/PatternMatching">PatternMatching v1.2.0</a>.</p>
9292
<p>If you need to migrate from older versions, first migrate to version 1.2.0. You can do that just by reading the
9393
changelog, because previous versions contained much fewer changes and it's much simpler to migrate.</p>
94-
<p>In order to migrate from version 2.0.0 to version 2.1.0 action is required only if you implemented the
94+
<p>In order to migrate from version 2.0.0 to version 2.1.0, action is required only if you implemented the
9595
<code>IPattern&lt;TInput, TMatchResult&gt;</code> interface (which wasn't recommended). The less generic <code>IPattern&lt;TInput&gt;</code> interface was
9696
removed, so you should remove its <code>Match</code> method. That's it.</p>
9797
<p>No changes are required to migrate from version 2.1.0 to 3.1.0. Version 3.0.0 removed support for .NET Standard 2.0, but
98-
version 3.1.0 added it back, effectively undoing the only breaking change of 3.0.0.</p>
98+
version 3.1.0 added it back, effectively undoing its only breaking change.</p>
9999
<h2 id="general">General</h2>
100100
<p>Since this library has a new name, the namespace is different as well. Instead of the <code>PatternMatching</code> namespace there
101101
are three namespaces: <code>Matchmaker</code>, <code>Matchmaker.Patterns</code> and <code>Matchmaker.Linq</code>.</p>

articles/patterns.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ <h2 id="the-ipatterntinput-tmatchresult-interface">The <code>IPattern&lt;TInput,
101101
<li>Matches the input value with the pattern and returns a successful result if the match is successful.</li>
102102
<li>Transforms the input value. The returned result contains the transformed value if it's successful.</li>
103103
</ul>
104-
<p>Since options are not supported natively in C#, a custom type <a href="results.html"><code>MatchResult&lt;T&gt;</code></a> is used.</p>
104+
<p>Since options are not supported natively in C#, a custom type <a href="results.html"><code>MatchResult&lt;T&gt;</code></a> is used.</p>
105105
<p>The definition of patterns is similar to F#'s active patterns.</p>
106-
<p>Descriptions for patterns are not terribly important, but can be useful for debugging. As such, they are optional if
106+
<p>Descriptions for patterns are not terribly important, but can be useful for debugging. As such, they are optional if
107107
you don't want a pattern to have a description, it should be empty. A pattern's description should never be <code>null</code>.</p>
108108
<h2 id="null-values">Null Values</h2>
109109
<p>The results of patterns' matching can be <code>null</code>. This is why the <code>MatchResult&lt;T&gt;</code> type can contain a <code>null</code> value.</p>
@@ -131,7 +131,7 @@ <h2 id="linq-to-patterns">LINQ to Patterns</h2>
131131
<p>The <code>Matchmaker.Linq</code> namespace provides several extension methods for patterns:</p>
132132
<ul>
133133
<li><code>Select</code> maps a pattern's result value if it's successful.</li>
134-
<li><code>Pipe</code> creates a pattern pipeline the result of the first pattern is the input of the second pattern.</li>
134+
<li><code>Pipe</code> creates a pattern pipeline the result of the first pattern is the input of the second pattern.</li>
135135
<li><code>Cast</code> casts a pattern's result to a specified type. It's the same as piping a pattern to the <code>Type</code> pattern. If the
136136
input is <code>null</code>, then the match will fail only if the destination type is a non-nullable value type.</li>
137137
<li><code>Bind</code> flat-maps a pattern's result. If a pattern's result is successful, it calls the specified function and passes
@@ -142,17 +142,17 @@ <h2 id="linq-to-patterns">LINQ to Patterns</h2>
142142
the input if successful.</li>
143143
<li><code>Compose</code> is the same as the three methods above, but the composition operator is passed to it as well.</li>
144144
<li><code>Cached</code> returns a pattern which matches the same as the specified pattern but caches its results in a <code>null</code>-safe
145-
hash table. Every input will be matched only once if it's matched again, the result will be taken from the cache. The
145+
hash table. Every input will be matched only once if it's matched again, the result will be taken from the cache. The
146146
caching process is not thread-safe.</li>
147147
</ul>
148148
<p>All extension methods for patterns are overloaded to take a custom description.</p>
149149
<p>Since there are the <code>Select</code> and <code>Where</code> extensions on patterns, you can write them using C#'s query syntax.</p>
150150
<p>Patterns have the <code>Bind</code> and <code>Return</code> functions, so they are monads. To be more specific, patterns can be thought of as
151151
a combination of the Reader and Maybe monads.</p>
152152
<h2 id="immutability">Immutability</h2>
153-
<p>Every predefined pattern as well as patterns returned by the <code>CreatePattern</code> and extension methods are immutable.
154-
Calling an extension method on a pattern returns a new pattern the old one is unchanged.</p>
155-
<p>An exception is the pattern returned by the <code>Cached</code> method, which is not immutable it holds a mutable cache. But if a
153+
<p>All predefined patterns, as well as patterns returned by <code>CreatePattern</code> and extension methods, are immutable. Calling
154+
an extension method on a pattern returns a new pattern the old one is unchanged.</p>
155+
<p>An exception is the pattern returned by the <code>Cached</code> method, which is not immutable it holds a mutable cache. But if a
156156
pattern is referentially transparent (its <code>Match</code> method always returns the same result for the same input and doesn't
157157
have any side effects), then the caching pattern based on it can be thought of as immutable as well, because it doesn't
158158
matter how many times the base pattern's <code>Match</code> method is called.</p>
@@ -170,7 +170,7 @@ <h3 id="the-easy-way">The Easy Way</h3>
170170
<h3 id="the-hard-way">The Hard Way</h3>
171171
<p>If you want something more complex than a single function, you can create a class which extends the
172172
<code>Matchmaker.Patterns.Pattern&lt;TInput, TMatchResult&gt;</code> class. This is a base class for patterns, and it implements the
173-
<code>Description</code> property which you don't have to use if you don't want by default the description is empty, which means
173+
<code>Description</code> property which you don't have to use if you don't want by default the description is empty, which means
174174
that the pattern doesn't have a description.</p>
175175
<p>You can also implement the <code>IPattern&lt;TInput, TMatchResult&gt;</code> interface directly. There is no reason to do that instead of
176176
extending the <code>Pattern&lt;TInput, TMatchResult&gt;</code> class unless your class already extends another class. But in that case,

articles/results.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ <h1 id="match-results">Match Results</h1>
9898
<li>Users may use a different library/framework for functional features. There are a lot of those for C#.</li>
9999
</ul>
100100
<p>So, starting with version 2, instead of using the <code>OptionUnsafe&lt;T&gt;</code> type from language-ext, this library includes a
101-
<code>MatchResult&lt;T&gt;</code> type. This type is much like optional types from other libraries in that it may contain a value, or may
102-
not, except for a couple differences:</p>
101+
<code>MatchResult&lt;T&gt;</code> type. This type works much like optional types from other libraries in that it may contain a value, or
102+
may not, except for a couple differences:</p>
103103
<ul>
104104
<li><code>MatchResult&lt;T&gt;</code> is not a general-purpose optional type and shouldn't be used as such.</li>
105105
<li><code>MatchResult&lt;T&gt;</code> can contain <code>null</code> values and this is important to remember. This type is not used to avoid

articles/unions.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ <h1 id="discriminated-unions">Discriminated Unions</h1>
148148
</code></pre>
149149
<p>As you can see, we have to throw an exception in the <code>switch</code> version, because C# can't know that <code>ConsCell</code> and <code>Empty</code>
150150
are the only possible subclasses of <code>ConsList</code>. And for that reason, if we forget to define one of the cases in <code>switch</code>
151-
or in a match, we'll get an exception. In F# a warning is issued when the match is incomplete, but C# doesn't have the
151+
or in a match, we'll get an exception. In F#, a warning is issued when the match is incomplete, but C# doesn't have the
152152
notion of complete or incomplete matches. Of course, this match will fail if the provided list is <code>null</code>, but this can
153153
be handled using the <code>Null</code> pattern.</p>
154154
<p>With C# 8, there's a better way to match on discriminated unions, but we still have to explicitly throw an exception in

0 commit comments

Comments
 (0)