@@ -10,23 +10,15 @@ Version 1.x can be found there. This repository contains version 2+.
1010
1111## Installation
1212
13- If your platform supports .NET Standard 2.1, you can install the latest version:
14-
15- ```
16- dotnet add package Matchmaker --version 3.0.1
17- ```
18-
19- If it doesn't, then stick to versions 2.x:
20-
2113```
22- dotnet add package Matchmaker --version 2.1.0
14+ dotnet add package Matchmaker
2315```
2416
2517## A Simple Example
2618
2719This is what the simplest match expression looks like:
2820
29- ```
21+ ``` c#
3022using static Matchmaker .Patterns .Pattern ;
3123
3224// ...
@@ -45,7 +37,7 @@ string result =
4537
4638This is what an equivalent ` switch ` statement looks like (pre-C# 8):
4739
48- ```
40+ ``` c#
4941string result ;
5042int i = 5 ;
5143
@@ -81,13 +73,13 @@ in an object, and use it multiple times on different input values.
8173- Like in ` switch ` the patterns are tried out sequentially. This means that the ` Any ` pattern should always
8274come last.
8375
84- C# 8 included a new way to write ` switch ` expressions which yield a value, and C# 9 extended it quite a bit. This
85- drastically reduced the need for external libraries like this one for pattern matching. However, this library lets the
86- user define arbitrary patterns, which makes this library more powerful than the ` switch ` expressions.
76+ C# 8 included a new way to write ` switch ` expressions which yield a value, and further versions extended it quite a bit.
77+ This drastically reduced the need for external libraries like this one for pattern matching. However, this library lets
78+ the user define arbitrary patterns, which makes this library more powerful than the ` switch ` expressions.
8779
88- Here's what the equivalent switch expression looks like in C# 8:
80+ Here's what the equivalent switch expression looks like in C# 8 or later :
8981
90- ```
82+ ``` c#
9183int i = 5 ;
9284
9385string result = i switch
@@ -101,14 +93,14 @@ string result = i switch
10193```
10294
10395OK, this is much shorter and cleaner than the previous two examples. But this library shines when the patterns are
104- more complex. While C# allowes various kinds of patterns, this library allows anything you can think about .
96+ more complex. While C# allows various kinds of patterns, this library allows anything you can think of .
10597
10698## Another Example
10799
108100Let's define a simple list, implemented as [ cons cells] ( https://en.wikipedia.org/wiki/Cons ) . This list is not
109101generic for simplicity.
110102
111- ```
103+ ``` c#
112104public abstract class ConsList
113105{
114106 private protected ConsList ()
@@ -143,7 +135,7 @@ public sealed class Empty : ConsList
143135Now let's look what pattern matching on the list would look like. Let's create
144136a function which finds the sum of all items of the list.
145137
146- ```
138+ ``` c#
147139public int Sum (ConsList list ) =>
148140 Match .Create <ConsList , int >()
149141 .Case <ConsCell >(cell => cell .Head + Sum (cell .Tail ))
@@ -155,7 +147,7 @@ public int Sum(ConsList list) =>
155147
156148Here is the equivalent function implemented using the ` switch ` statement (pre-C# 8):
157149
158- ```
150+ ``` c#
159151public int Sum (ConsList list )
160152{
161153 switch (list )
@@ -172,13 +164,13 @@ public int Sum(ConsList list)
172164
173165As you can see, we have to throw an exception in the ` switch ` version, because C# can't know that ` ConsCell `
174166and ` Empty ` are the only possible subclasses of ` ConsList ` . And for that reason, if we forget to define one
175- of the cases in ` switch ` or in a match, we'll get an exception. In F# a warning is issued when the match is
167+ of the cases in ` switch ` or in a match, we'll get an exception. In F#, a warning is issued when the match is
176168incomplete, but C# doesn't have the notion of complete or incomplete matches.
177169
178170With C# 8 there's a better way to do this, but we still have to explicitly throw an exception
179171in the default case (which we know won't happen):
180172
181- ```
173+ ``` c#
182174public int Sum (ConsList list ) =>
183175 list switch
184176 {
@@ -192,11 +184,11 @@ public int Sum(ConsList list) =>
192184## Matching with Fall-through
193185
194186C, C++ and, Java support fall-through in ` switch ` statements. So does this library, although it works differently here.
195- You can read more [ here] ( https://matchmaker.tolik.io/v3.0.1/ articles/expressions.html#matching-with-fall-through ) .
187+ You can read more [ here] ( https://matchmaker.tolik.io/articles/expressions.html#matching-with-fall-through ) .
196188
197189Here's an implementation of the famous fizz-buzz program which uses matching with fall-through:
198190
199- ```
191+ ``` c#
200192using System .Linq ;
201193
202194using Matchmaker ;
@@ -218,7 +210,8 @@ var result = Enumerable.Range(0, 15)
218210 .Select (items => items .Aggregate (String .Concat ))
219211 .ToList ();
220212
221- // The result is ("FizzBuzz", "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz");
213+ // The result is:
214+ // "FizzBuzz", "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", "11", "Fizz", "13", "14", "FizzBuzz"
222215```
223216
224217## Static Match Expressions
@@ -227,7 +220,7 @@ One pain point of match expressions is that whenever a method which contains a m
227220expression is initialized from scratch every time. This can be solved with static match expressions. Take a look at
228221the revised simple example:
229222
230- ```
223+ ``` c#
231224string result = Match .CreateStatic <int , string >(match => match
232225 .Case (EqualTo (1 ), _ => " one" )
233226 .Case (EqualTo (2 ), _ => " two" )
@@ -238,37 +231,31 @@ string result = Match.CreateStatic<int, string>(match => match
238231```
239232
240233Now this match expression will be initialized only once even if its containing method is executed multiple times.
241- You can read more [ here] ( https://matchmaker.tolik.io/v3.0.1/ articles/expressions.html#static-match-expressions ) .
234+ You can read more [ here] ( https://matchmaker.tolik.io/articles/expressions.html#static-match-expressions ) .
242235
243236## More Info
244237
245- If you want to learn how to use this library, you should read the [ documentation] ( https://matchmaker.tolik.io/v3.0.1 ) .
238+ If you want to learn how to use this library, you should read the [ documentation] ( https://matchmaker.tolik.io ) .
246239The articles provide everything you need to know to use this library.
247240
248- If you need extensive information, go to the [ API reference] ( https://matchmaker.tolik.io/v3.0.1/ api/index.html ) .
241+ If you need extensive information, go to the [ API reference] ( https://matchmaker.tolik.io/api/index.html ) .
249242
250243If you need even more info about this library, you can go through the
251- [ tests] ( https://github.com/TolikPylypchuk/Matchmaker/tree/v3.0.1/ Matchmaker.Tests ) . They are property-based and as such
244+ [ tests] ( https://github.com/TolikPylypchuk/Matchmaker/Matchmaker.Tests ) . They are property-based and as such
252245they describe every aspect of the classes and their members.
253246
254- The documentation can be found here:
255-
256- - Version 3.0.1: https://matchmaker.tolik.io/v3.0.1
257- - Version 3.0.0: https://matchmaker.tolik.io/v3.0.0
258- - Version 2.1.0: https://matchmaker.tolik.io/v2.1.0
259- - Version 2.0.0: https://matchmaker.tolik.io/v2.0.0
260- - Older versions: https://github.com/TolikPylypchuk/PatternMatching
261-
262247## Is This Library Still Maintained?
263248
264- I'm not planning on writing new versions beyond 3.0 (or maybe 3.1 if some stuff needs fixing). To be fair, I thought
249+ I'm not planning on writing new versions beyond 3.1 (or maybe 3.2 if some stuff needs fixing). To be fair, I thought
265250the same thing after releasing version 1.1 and yet here we are. This time I do believe that this library has enough
266- features (probably more than enough). Maybe one day I'll revisit this decision, but for now (January 2022 ) this is it;
251+ features (probably more than enough). Maybe one day I'll revisit this decision, but for now (June 2025 ) this is it;
267252this is as good as it gets.
268253
269254That said, if you report a bug or request a new feature, I'll definitely look into it. I'm not giving up on this
270255library any time soon.
271256
272- ## License
257+ ## Icon
273258
274- [ MIT License] ( https://github.com/TolikPylypchuk/Matchmaker/blob/master/LICENSE )
259+ Icon made by [ Roundicons] ( https://www.flaticon.com/authors/roundicons ) from
260+ [ www.flaticon.com ] ( https://www.flaticon.com ) and is licensed by
261+ [ CC 3.0 BY] ( http://creativecommons.org/licenses/by/3.0/ ) .
0 commit comments