Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ public void Execute_executes_action()
property.Should().Be("Some value");
}

[Fact]
public void Execute_returns_func_result()
{
Maybe<MyClass> maybe = new MyClass { Property = "Some value" };

string property = maybe.Execute(x => x.Property);

property.Should().Be("Some value");
}

private static Maybe<string> GetPropertyIfExists(MyClass myClass)
{
Expand Down
9 changes: 9 additions & 0 deletions CSharpFunctionalExtensions/MaybeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,14 @@ public static void Execute<T>(this Maybe<T> maybe, Action<T> action)

action(maybe.Value);
}

public static TOut Execute<T, TOut>(this Maybe<T> maybe, Func<T, TOut> func)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like Map method, not like Execute or Select

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Select == Map in C#. Found some conflicts merging this PR. Could you re-submit?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@a-z-hub Ping!
Is this still active?

where T : class
{
if (maybe.HasNoValue)
return default(TOut);

return func(maybe.Value);
}
}
}