Created
November 18, 2016 15:06
-
-
Save stdray/355cfbed30419dd0fd69efbbd1e91700 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using StreamExtensions; | |
module Program | |
{ | |
Main() : void | |
{ | |
def stream = MemoryStream(); | |
ignore(stream << 108 << 111 << 108); | |
stream.Position = 0; | |
def reader = StreamReader(stream); | |
Console.WriteLine(reader.ReadToEnd()); | |
stream.Position = 0; | |
def x = Ref(); def y = Ref(); def z = Ref(); | |
ignore(stream >> x >> y >> z); | |
Console.WriteLine($"$x $y $z"); | |
_ = Console.ReadLine(); | |
} | |
} | |
public class Ref[T] | |
{ | |
public Value : T { get; set } | |
public override ToString() : string | |
{ | |
if(Object.ReferenceEquals(Value, null)) | |
"null" | |
else | |
Value.ToString() | |
} | |
} | |
module StreamExtensions | |
{ | |
public @<<(stream : Stream, v : byte) : Stream | |
{ | |
stream.WriteByte(v); | |
stream | |
} | |
public @>>(stream : Stream, v : Ref[int]) : Stream | |
{ | |
v.Value = stream.ReadByte(); | |
stream | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment