This file contains hidden or 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.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) |
This file contains hidden or 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
var rb = RegistrationBuilder.ForDelegate((c, p) => | |
{ | |
TService? instance = (TService?)p | |
.OfType<TypedParameter>() | |
.FirstOrDefault(tp => tp.Type == typeof(TService)) | |
?.Value; | |
if (instance == null) | |
{ |
This file contains hidden or 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
export type Product = () => number; | |
export var ProductA: (price: number) => Product = (price: number) => () => price; | |
export var Packaging: (product: Product) => Product = (product: Product) => () => product() + 0.5; |
This file contains hidden or 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
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 | |
}); |
This file contains hidden or 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
export interface Product { getPrice(): number; } | |
export class ProductA implements Product { | |
private _price: number; | |
constructor(price: number) { | |
this._price = price; | |
} | |
getPrice(): number { | |
return this._price; |
This file contains hidden or 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
@FunctionalInterface | |
public interface SupplierFunctor<T> extends Supplier<T> { | |
default <T1> SupplierFunctor<T1> andThen(Function<T, T1> f) { | |
return () -> f.apply(this.get()); | |
} | |
} |
This file contains hidden or 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
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 |
This file contains hidden or 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
@FunctionalInterface | |
public interface DiscountStrategy { | |
double getDiscounted(double discount, double price); | |
} |
This file contains hidden or 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
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()), | |
}; |
This file contains hidden or 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
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() | |
}; |