Skip to content

Commit

Permalink
Enhance IO Monad with new robustness and utilities
Browse files Browse the repository at this point in the history
Added extensive functionality to the IO Monad, including local cancellation, retry, repeat, and fold mechanisms to improve resource management and scheduling options. Updated method implementations and removed obsolete functionality for improved consistency and performance.
  • Loading branch information
louthy committed Feb 14, 2025
1 parent 1addbfd commit 55da8d9
Show file tree
Hide file tree
Showing 33 changed files with 1,152 additions and 484 deletions.
12 changes: 6 additions & 6 deletions LanguageExt.Core/Common/Errors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,22 @@ public static class Errors
public static readonly Error LiftIONotSupported = (LiftIONotSupportedCode, LiftIONotSupportedText);

/// <summary>
/// Transformer stack has no unliftIO support error text
/// Transformer stack has no `ToIO` support error text
/// </summary>
public const string UnliftIONotSupportedText =
public const string ToIONotSupportedText =
"The IO monad is not in the monad-transformer stack or MonadIO.ToIO has not been implemented in the trait " +
"implementation for your monad-type. Therefore it's not possible to leverage `MonadIO` unlifting trait " +
"functionality. To resolve this, implement `MonadIO.ToIO` and/or `MonadIO,MapIO`.";

/// <summary>
/// Transformer stack has no unliftIO support error code
/// Transformer stack has no `ToIO` support error code
/// </summary>
public const int UnliftIONotSupportedCode = -2000000008;
public const int ToIONotSupportedCode = -2000000008;

/// <summary>
/// Transformer stack has no unliftIO support error
/// Transformer stack has no `ToIO` support error
/// </summary>
public static readonly Error UnliftIONotSupported = (UnliftIONotSupportedCode, UnliftIONotSupportedText);
public static readonly Error ToIONotSupported = (ToIONotSupportedCode, ToIONotSupportedText);

/// <summary>
/// End-of-stream error text
Expand Down
2 changes: 1 addition & 1 deletion LanguageExt.Core/Common/Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class Exceptions
/// <summary>
/// Transformer stack has no unliftIO support error
/// </summary>
public static readonly ExceptionalException UnliftIONotSupported = new (Errors.UnliftIONotSupportedText, Errors.UnliftIONotSupportedCode);
public static readonly ExceptionalException UnliftIONotSupported = new (Errors.ToIONotSupportedText, Errors.ToIONotSupportedCode);

/// <summary>
/// End-of-stream error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public static Eff<D> SelectMany<A, B, C, D>(
this (K<Eff, A> First, K<Eff, B> Second) self,
Func<(A First, B Second), K<Eff, C>> bind,
Func<(A First, B Second), C, D> project) =>
self.ZipIO().Bind(ab => bind(ab).Map(c => project(ab, c))).As();
self.Zip().Bind(ab => bind(ab).Map(c => project(ab, c))).As();

/// <summary>
/// Monadic bind and project with paired IO monads
Expand All @@ -172,7 +172,7 @@ public static Eff<D> SelectMany<A, B, C, D>(
this K<Eff, A> self,
Func<A, (K<Eff, B> First, K<Eff, C> Second)> bind,
Func<A, (B First, C Second), D> project) =>
self.As().Bind(a => bind(a).ZipIO().Map(cd => project(a, cd)));
self.As().Bind(a => bind(a).Zip().Map(cd => project(a, cd)));

/// <summary>
/// Monadic bind and project with paired IO monads
Expand All @@ -181,7 +181,7 @@ public static Eff<E> SelectMany<A, B, C, D, E>(
this (K<Eff, A> First, K<Eff, B> Second, K<Eff, C> Third) self,
Func<(A First, B Second, C Third), K<Eff, D>> bind,
Func<(A First, B Second, C Third), D, E> project) =>
self.ZipIO().Bind(ab => bind(ab).Map(c => project(ab, c))).As();
self.Zip().Bind(ab => bind(ab).Map(c => project(ab, c))).As();

/// <summary>
/// Monadic bind and project with paired IO monads
Expand All @@ -190,5 +190,5 @@ public static Eff<E> SelectMany<A, B, C, D, E>(
this K<Eff, A> self,
Func<A, (K<Eff, B> First, K<Eff, C> Second, K<Eff, D> Third)> bind,
Func<A, (B First, C Second, D Third), E> project) =>
self.As().Bind(a => bind(a).ZipIO().Map(cd => project(a, cd)));
self.As().Bind(a => bind(a).Zip().Map(cd => project(a, cd)));
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using LanguageExt.Common;
using LanguageExt.Traits;
using static LanguageExt.Prelude;

namespace LanguageExt;

Expand Down Expand Up @@ -185,7 +182,7 @@ public static Eff<RT, D> SelectMany<RT, A, B, C, D>(
this (K<Eff<RT>, A> First, K<Eff<RT>, B> Second) self,
Func<(A First, B Second), K<Eff<RT>, C>> bind,
Func<(A First, B Second), C, D> project) =>
self.ZipIO().Bind(ab => bind(ab).Map(c => project(ab, c))).As();
self.Zip().Bind(ab => bind(ab).Map(c => project(ab, c))).As();

/// <summary>
/// Monadic bind and project with paired IO monads
Expand All @@ -194,7 +191,7 @@ public static Eff<RT, D> SelectMany<RT, A, B, C, D>(
this K<Eff<RT>, A> self,
Func<A, (K<Eff<RT>, B> First, K<Eff<RT>, C> Second)> bind,
Func<A, (B First, C Second), D> project) =>
self.As().Bind(a => bind(a).ZipIO().Map(cd => project(a, cd)));
self.As().Bind(a => bind(a).Zip().Map(cd => project(a, cd)));

/// <summary>
/// Monadic bind and project with paired IO monads
Expand All @@ -203,7 +200,7 @@ public static Eff<RT, E> SelectMany<RT, A, B, C, D, E>(
this (K<Eff<RT>, A> First, K<Eff<RT>, B> Second, K<Eff<RT>, C> Third) self,
Func<(A First, B Second, C Third), K<Eff<RT>, D>> bind,
Func<(A First, B Second, C Third), D, E> project) =>
self.ZipIO().Bind(ab => bind(ab).Map(c => project(ab, c))).As();
self.Zip().Bind(ab => bind(ab).Map(c => project(ab, c))).As();

/// <summary>
/// Monadic bind and project with paired IO monads
Expand All @@ -212,5 +209,5 @@ public static Eff<RT, E> SelectMany<RT, A, B, C, D, E>(
this K<Eff<RT>, A> self,
Func<A, (K<Eff<RT>, B> First, K<Eff<RT>, C> Second, K<Eff<RT>, D> Third)> bind,
Func<A, (B First, C Second, D Third), E> project) =>
self.As().Bind(a => bind(a).ZipIO().Map(cd => project(a, cd)));
self.As().Bind(a => bind(a).Zip().Map(cd => project(a, cd)));
}
Loading

0 comments on commit 55da8d9

Please sign in to comment.