Skip to content

Instantly share code, notes, and snippets.

Avatar
💤
hibernating

Alexey Golub Tyrrrz

💤
hibernating
View GitHub Profile
@Tyrrrz
Tyrrrz / LINQ_for_tasks.cs
Created Dec 11, 2020
Monadic comprehensions via LINQ
View LINQ_for_tasks.cs
public static class TaskExtensions
{
public static async Task<TOut> SelectMany<TIn, TJoin, TOut>(
this Task<TIn> source,
Func<TIn, Task<TJoin>> join,
Func<TIn, TJoin, TOut> transform)
{
var sourceResult = await source;
var joinResult = await join(sourceResult);
return transform(sourceResult, joinResult);
@Tyrrrz
Tyrrrz / ResultMagic.cs
Created Feb 26, 2020
Return type inference in C# via delayed initialization and implicit conversion
View ResultMagic.cs
public class Result<TResult, TError>
{
private readonly TResult _result;
private readonly TError _error;
private readonly bool _isError;
private Result(TResult result, TError error, bool isError)
{
_result = result;
_error = error;
@Tyrrrz
Tyrrrz / Json.fs
Last active Oct 1, 2020
Parsing in F# with FParsec (final project)
View Json.fs
namespace Xmlparser
type JsonNode =
// Literals
| JsonNull // null
| JsonBool of bool // true | false
| JsonNumber of float // 10 | 5.63
| JsonString of string // "foobar"
// Complex types
| JsonArray of List<JsonNode> // [ "hello", 10, true ]
View Parsing-with-FParsec.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.