Files
RobustToolbox/Robust.Shared/Toolshed/Commands/Math/ListCommands.cs
Leon Friedrich 23a23f7c22 Misc toolshed fixes (#5340)
* Prevent map/emplace command errors from locking up the server

* Fix EmplaceCommand

* Fix sort commands

* Fix JoinCommand

* changelog

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2024-08-28 12:22:47 +10:00

56 lines
1.3 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Robust.Shared.Toolshed.Syntax;
namespace Robust.Shared.Toolshed.Commands.Math;
[ToolshedCommand]
public sealed class JoinCommand : ToolshedCommand
{
[CommandImplementation]
public string Join(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] string x,
[CommandArgument] ValueRef<string> y
)
{
var yVal = y.Evaluate(ctx);
if (yVal is null)
return x;
return x + yVal;
}
[CommandImplementation, TakesPipedTypeAsGeneric]
public IEnumerable<T> Join<T>(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] IEnumerable<T> x,
[CommandArgument] ValueRef<IEnumerable<T>> y
)
{
var yVal = y.Evaluate(ctx);
if (yVal is null)
return x;
return x.Concat(yVal);
}
}
[ToolshedCommand]
public sealed class AppendCommand : ToolshedCommand
{
[CommandImplementation, TakesPipedTypeAsGeneric]
public IEnumerable<T> Append<T>(
[CommandInvocationContext] IInvocationContext ctx,
[PipedArgument] IEnumerable<T> x,
[CommandArgument] ValueRef<T> y
)
{
var yVal = y.Evaluate(ctx);
if (yVal is null)
return x;
return x.Append(yVal);
}
}