Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc for maybe extension pt1 #44

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Maybe.Documentation/Maybe.Documentation.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Maybe\Maybe.csproj" />
</ItemGroup>

</Project>
145 changes: 145 additions & 0 deletions Maybe.Documentation/MaybeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
using ZBRA.Maybe;

namespace Maybe.Documentation
{
public class MaybeExtensions
{
public static void OrEmptyExample_WithValue()
{
Console.WriteLine("OrEmpty example with values");
var maybe = "some value".ToMaybe();
var v = maybe.OrEmpty();
Console.WriteLine($"Print Value: {v}");
// Print Value: some value
}

public static void OrEmptyExample_WithoutValue()
{
Console.WriteLine("OrEmpty example without values");
var maybe = Maybe<string>.Nothing;
var v = maybe.OrEmpty();
Console.WriteLine($"Print Value: {v}");
// Print Value:
}

public static void OrNullExample_WithValue()
{
Console.WriteLine("OrNull example with values");
var maybe = "some value".ToMaybe();
var v = maybe.OrNull();
Console.WriteLine($"Print Value: {v}");
// Print Value: some value
}

public static void OrNullExample_WithoutValue()
{
Console.WriteLine("OrNull example without values");
var maybe = Maybe<string>.Nothing;
var v = maybe.OrNull();
Console.WriteLine($"Print Value: {v}");
// Print Value:
}


public static void OrTrueExample_WithValue()
{
Console.WriteLine("OrTrue example with values");
var maybe = false.ToMaybe();
var v = maybe.OrTrue();
Console.WriteLine($"Print Value: {v}");
// Print Value: false
}

public static void OrTrueExample_WithoutValue()
{
Console.WriteLine("OrTrue example without values");
var maybe = Maybe<bool>.Nothing;
var v = maybe.OrTrue();
Console.WriteLine($"Print Value: {v}");
// Print Value: true
}

public static void OrFalseExample_WithValue()
{
Console.WriteLine("OrFalse example with values");
var maybe = false.ToMaybe();
var v = maybe.OrFalse();
Console.WriteLine($"Print Value: {v}");
// Print Value: False
}

public static void OrFalseExample_WithoutValue()
{
Console.WriteLine("OrFalse example without values");
var maybe = Maybe<bool>.Nothing;
var v = maybe.OrFalse();
Console.WriteLine($"Print Value: {v}");
// Print Value: False
}

internal static void ToNullableExample_WithValue()
{
Console.WriteLine("ToNullable example with value");
var maybe = 1234.ToMaybe();
var v = maybe.ToNullable();
Console.WriteLine($"Print Value: {v}");
// Print Value: 1234
}

internal static void ToNullableExample_WithoutValue()
{
Console.WriteLine("ToNullable example without value");
var maybe = Maybe<int>.Nothing;
var v = maybe.ToNullable();
Console.WriteLine($"Print Value: {v}");
// Print Value:
}

internal static void ToMaybeExample_WithObjectValue()
{
Console.WriteLine("ToMaybe example with object");
var myObject = new { PropertyA = "Value Of Property A", PropertyB = 66 };
var maybe = myObject.ToMaybe();
Console.WriteLine($"Print Value: {maybe}");
// Print Value: { PropertyA = Value Of Property A, PropertyB = 66 }
Console.WriteLine($"Maybe PropertyA value: {maybe.Select(o => o.PropertyA)}");
// Maybe PropertyA value: Value Of Property A
Console.WriteLine($"Maybe PropertyB value: {maybe.Select(o => o.PropertyB)}");
// Maybe PropertyB value: 66
}

internal static void ToMaybeExample_WithStructValue()
{
Console.WriteLine("ToMaybe example with struct");
var myInt = 66;
var maybe = myInt.ToMaybe();
Console.WriteLine($"Print Value: {maybe}");
// Print Value: 66
Console.WriteLine($"Print Maybe value: {maybe.Select(i => i)}");
//Print Maybe value: 66
}

internal static void ToMaybeExample_WithMaybeValue()
{
Console.WriteLine("ToMaybe example with a Maybe of an object");
var myObject = new { PropertyA = "Value Of Property A", PropertyB = 66 };
var maybe = myObject.ToMaybe();
var secondMaybe = maybe.ToMaybe();
Console.WriteLine($"First Maybe Print Value: {maybe}");
// First Maybe Print Value: { PropertyA = Value Of Property A, PropertyB = 66 }
Console.WriteLine($"Second Maybe Print Value: {secondMaybe}");
// Second Maybe Print Value: { PropertyA = Value Of Property A, PropertyB = 66 }
}

internal static void ToMaybeExample_WithMaybeNothingValue()
{
Console.WriteLine("ToMaybe example with a Maybe of an object");
var maybe = Maybe<string>.Nothing;
var secondMaybe = maybe.ToMaybe();
Console.WriteLine($"First Maybe Print Value: {maybe}");
// First Maybe Print Value:
Console.WriteLine($"Second Maybe Print Value: {secondMaybe}");
// Second Maybe Print Value:
}
}
}
27 changes: 27 additions & 0 deletions Maybe.Documentation/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Maybe.Documentation;

//OrEmpty
MaybeExtensions.OrEmptyExample_WithValue();
MaybeExtensions.OrEmptyExample_WithoutValue();
//OrNull
MaybeExtensions.OrNullExample_WithValue();
MaybeExtensions.OrNullExample_WithoutValue();
//OrTrue
MaybeExtensions.OrTrueExample_WithValue();
MaybeExtensions.OrTrueExample_WithoutValue();
//OrFalse
MaybeExtensions.OrFalseExample_WithValue();
MaybeExtensions.OrFalseExample_WithoutValue();


//ToNullable
MaybeExtensions.ToNullableExample_WithValue();
MaybeExtensions.ToNullableExample_WithoutValue();

//ToMaybe
MaybeExtensions.ToMaybeExample_WithObjectValue();
MaybeExtensions.ToMaybeExample_WithStructValue();
MaybeExtensions.ToMaybeExample_WithMaybeValue();
MaybeExtensions.ToMaybeExample_WithMaybeNothingValue();

Console.ReadLine();
12 changes: 9 additions & 3 deletions Maybe.sln
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30717.126
# Visual Studio Version 17
VisualStudioVersion = 17.4.33213.308
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Maybe.Test", "Maybe.Test\Maybe.Test.csproj", "{F5DD5CA7-C20A-4E6A-A06A-1C4118D10945}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Maybe", "Maybe\Maybe.csproj", "{15B03988-B848-41CC-9B68-1BA4AB16A78F}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Maybe", "Maybe\Maybe.csproj", "{15B03988-B848-41CC-9B68-1BA4AB16A78F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Maybe.Documentation", "Maybe.Documentation\Maybe.Documentation.csproj", "{AAB025E0-8341-4A7B-9B65-115430DED230}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -21,6 +23,10 @@ Global
{15B03988-B848-41CC-9B68-1BA4AB16A78F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{15B03988-B848-41CC-9B68-1BA4AB16A78F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{15B03988-B848-41CC-9B68-1BA4AB16A78F}.Release|Any CPU.Build.0 = Release|Any CPU
{AAB025E0-8341-4A7B-9B65-115430DED230}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AAB025E0-8341-4A7B-9B65-115430DED230}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AAB025E0-8341-4A7B-9B65-115430DED230}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AAB025E0-8341-4A7B-9B65-115430DED230}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,8 @@ if (a < b)
{
// Nothing will always be less than any int value
}
```
```

# See more details

[Maybe Extension](docs/maybe-extension.md)
Loading