Skip to content

Commit 72d8ded

Browse files
committed
Remove unneeded constraints on Reducers
1 parent fe22df3 commit 72d8ded

3 files changed

Lines changed: 23 additions & 19 deletions

File tree

LanguageExt.Streaming/SourceT/Extensions/SourceT.Extensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
using System.Diagnostics.Contracts;
44
using System.Threading.Channels;
55
using LanguageExt.Common;
6-
using LanguageExt.Pipes;
76
using LanguageExt.Traits;
8-
using static LanguageExt.Prelude;
97

108
namespace LanguageExt;
119

LanguageExt.Streaming/SourceT/Extensions/SourceT.Reducers.cs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ namespace LanguageExt;
77

88
public static partial class SourceTExtensions
99
{
10-
/// <param name="ma"></param>
10+
/// <param name="ma"></param>
1111
/// <typeparam name="M"></typeparam>
1212
/// <typeparam name="A"></typeparam>
13-
extension<M, A>(K<SourceT<M>, A> ma) where M : MonadIO<M>, Alternative<M>
13+
extension<M, A>(K<SourceT<M>, A> ma) where M : MonadIO<M>
1414
{
1515
/// <summary>
1616
/// Force iteration of the stream, yielding a unit `M` structure.
@@ -22,20 +22,6 @@ public static partial class SourceTExtensions
2222
public K<M, Unit> Iter() =>
2323
ma.As().FoldReduce(unit, (_, _) => unit);
2424

25-
/// <summary>
26-
/// Force iteration of the stream, yielding the last structure processed
27-
/// </summary>
28-
[Pure]
29-
public K<M, A> Last() =>
30-
M.Token.Bind(t =>
31-
ma.As()
32-
.FoldReduce(Option<A>.None, (_, x) => Some(x))
33-
.Bind(ma => ma switch
34-
{
35-
{ IsSome: true, Case: A value } => M.Pure(value),
36-
_ => M.Empty<A>()
37-
}));
38-
3925
/// <summary>
4026
/// Collect all the values into a `Seq` while the predicate holds.
4127
/// </summary>
@@ -66,5 +52,25 @@ public K<M, Seq<A>> CollectUntil(Func<(Seq<A> Items, A Item), bool> predicate) =
6652
[Pure]
6753
public K<M, Seq<A>> Collect() =>
6854
ma.As().FoldReduce<Seq<A>>([], (xs, x) => xs.Add(x));
55+
}
56+
57+
/// <param name="ma"></param>
58+
/// <typeparam name="M"></typeparam>
59+
/// <typeparam name="A"></typeparam>
60+
extension<M, A>(K<SourceT<M>, A> ma) where M : MonadIO<M>, Alternative<M>
61+
{
62+
/// <summary>
63+
/// Force iteration of the stream, yielding the last structure processed
64+
/// </summary>
65+
[Pure]
66+
public K<M, A> Last() =>
67+
M.Token.Bind(t =>
68+
ma.As()
69+
.FoldReduce(Option<A>.None, (_, x) => Some(x))
70+
.Bind(ma => ma switch
71+
{
72+
{ IsSome: true, Case: A value } => M.Pure(value),
73+
_ => M.Empty<A>()
74+
}));
6975
}
7076
}

LanguageExt.Streaming/SourceT/SourceT.Module.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,5 +370,5 @@ public static K<M, Seq<A>> collectUntil<M, A>(
370370
[Pure]
371371
public static K<M, Seq<A>> collect<M, A>(K<SourceT<M>, A> ma)
372372
where M : MonadIO<M> =>
373-
ma.As().FoldReduce<Seq<A>>([], (xs, x) => xs.Add(x));
373+
ma.As().FoldReduce<Seq<A>>([], (xs, x) => xs.Add(x));
374374
}

0 commit comments

Comments
 (0)