Package ID: VisualBasicFunctionalExtensions
Version: 0.0.5
Owner: Justi
License: MIT
VisualBasicFunctionalExtensions is a functional library for Visual Basic .NET 2.0, drawing inspiration from Rust's functional programming concepts. The library is designed without a focus on performance, making it suitable for various applications.
Install via NuGet Package Manager Console:
dotnet add package VisualBasicFunctionalExtensions --version 0.0.5
- Result and Maybe Monads
Introduction to all the methods and function the library has to offer.
[Try](Of T, E)(func As Func(Of T), onError As Func(Of Exception, E)) As Result(Of T, E)
Private Const expectedMessage = "Can not sqrt negative integers"
Public Function CustomSqrt(x As Integer) As Double
If x < 0 Then
Throw New Exception(expectedMessage)
Else
Return Math.Sqrt(x)
End If
End Function
Public Sub ExampleNoException()
Dim value = 15
Dim expected = Result(Of Double, String).Ok(CustomSqrt(value))
Dim res = Result(Of Double, String).
Try(
Function() CustomSqrt(value),
Function(exception) exception.Message
)
Assert.AreEqual(expected, res)
End Sub
Public Sub ExampleCatchException()
Dim value = -1
Dim expected = Result(Of Double, String).Err(errorValue:=expectedMessage)
Dim res = Result(Of Double, String).
Try(
Function() CustomSqrt(value),
Function(exception) exception.Message
)
Assert.AreEqual(expected, res)
End Sub
Justin Kasteleijn Nadia Alrayes
MIT License
(c) Justin Kasteleijn 2024
For bug reports, visit the GitHub repository.