Skip to content

Instantly share code, notes, and snippets.

@Pzixel
Pzixel / Main.cs
Last active October 17, 2019 23:07
void Main()
{
var v = from x in 10.AsResult()
from y in 0.AsResult()
select Result.Try (() => x/y);
v.Dump();
}
@Pzixel
Pzixel / flow.cs
Created September 16, 2019 11:57
var graph = GraphDsl.Create(b =>
{
b.From(new RabbitSource<StartProcessTriggerMessage>(workerSettings.RoutingKey, mqFactory))
.Via(Flow.Create<RabbitMessage<StartProcessTriggerMessage>>()
.SelectAsync(Environment.ProcessorCount, async message =>
{
var stateInfoResult = await Result.TryAsync(() =>
RetryApiFuncAsync(() => GetOmsStateInfoApiClient(
message.Data.Trigger.PrincipalToken,
message.Data.Trigger.RequestId)
@Pzixel
Pzixel / Main.cs
Last active September 29, 2019 17:41
Haskell vs GO: Tree mapping
using System;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
class Program
{
class Comment
void Main()
{
var files = Directory.EnumerateFiles(@"C:\Users\me\Documents\Repos\myrepo\", "*.csproj", SearchOption.AllDirectories);
foreach (var csprojPath in files)
{
PatchCsProj(csprojPath);
}
}
void PatchCsProj(string path)
public static class XEnumerable
{
public static (T1[], T2[]) Unzip<T1, T2>(this IEnumerable<(T1 x, T2 y)> source)
{
if (source is IReadOnlyCollection<(T1, T2)> roc)
{
T1[] xs = new T1[roc.Count];
T2[] ys = new T2[roc.Count];
int i = 0;
foreach (var (x, y) in source)
using System;
namespace ConsoleApp28
{
public readonly struct Unit
{
public static Unit Instance { get; } = new Unit();
}
public class State<S, A>
pragma solidity ^0.5.2;
contract Owned {
address public owner;
constructor() public {
owner = tx.origin;
}
modifier onlyOwner {
using System;
using System.Linq;
using Newtonsoft.Json;
namespace XXX
{
[JsonConverter(typeof(StructWrapperConverter))]
public sealed class StructWrapper<T> where T : struct
{
public T Value { get; }
module Main
import Debug.Trace
import Data.Vect;
-- infix 4 :+:
-- data Vect : Nat -> Type -> Type where
-- Nil : Vect Z a
-- (:+:) : a -> Vect k a -> Vect (S k) a
module Main
%default total
data Vect : Nat -> Type -> Type where
Nil : Vect Z a
(::) : a -> Vect k a -> Vect (S k) a
data Elem : a -> Vect k a -> Type where
Here : Elem x (x :: xs)