Skip to content

Instantly share code, notes, and snippets.

View dimitris-papadimitriou-chr's full-sized avatar
📖
Cloud Design Patterns

Dimitris Papadimitriou dimitris-papadimitriou-chr

📖
Cloud Design Patterns
View GitHub Profile
using System;
using System.Collections.Generic;
using System.Linq;
using LanguageExt;
namespace PracticalCSharp.Either.Monad.Exception
{
public static partial class FunctionalExtensions
{
public static T GetOrThrowException<T>(this Either<string, T> @either)
var rb = RegistrationBuilder.ForDelegate((c, p) =>
{
TService? instance = (TService?)p
.OfType<TypedParameter>()
.FirstOrDefault(tp => tp.Type == typeof(TService))
?.Value;
if (instance == null)
{
export type Product = () => number;
export var ProductA: (price: number) => Product = (price: number) => () => price;
export var Packaging: (product: Product) => Product = (product: Product) => () => product() + 0.5;
export interface Product { getPrice: () => number;}
export var ProductA: (price: number) => Product = (price: number) => ({
getPrice: () => price
});
export var Packaging: (product: Product) => Product = (product: Product) => ({
getPrice: () => product.getPrice() + 0.5
});
export interface Product { getPrice(): number; }
export class ProductA implements Product {
private _price: number;
constructor(price: number) {
this._price = price;
}
getPrice(): number {
return this._price;
@FunctionalInterface
public interface SupplierFunctor<T> extends Supplier<T> {
default <T1> SupplierFunctor<T1> andThen(Function<T, T1> f) {
return () -> f.apply(this.get());
}
}
import { log } from "./log.js";
import { State } from "./state.js";
import { match } from "./utils.js";
// javascript implementation of the example - 1 of the State monad in hasklell
//https://wiki.haskell.org/State_Monad#Complete_and_Concrete_Example_1
var playGame = charSequence =>
match(charSequence)({
// pattern matching on the array
empty: () => State(s => s), //terminates
@FunctionalInterface
public interface DiscountStrategy {
double getDiscounted(double discount, double price);
}
public static partial class FunctionalExt
{
public static Tree<T> Reverse<T>(this Tree<T> @this) =>
@this switch
{
Leaf<T> { Value: var v } => new Leaf<T>(v),
Node<T> { Left: var l, Value: var v, Right: var r } =>
new Node<T>(r.Reverse(), v, l.Reverse()),
};
public static partial class FunctionalExt
{
public static Tree<T> Reverse<T>(this Tree<T> @this) =>
@this switch
{
Leaf<T> { Value: var v } => {...},
Node<T> { Left: var l, Value: var v, Right: var r } => {...},
_ => throw new NotImplementedException()
};