Skip to content

Instantly share code, notes, and snippets.

Afif Mohammed afifmohammed

Block or report user

Report or block afifmohammed

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@afifmohammed
afifmohammed / io_interpreter_via_yield.cs
Last active Jul 17, 2019
Interpreting IO vai the yield operator
View io_interpreter_via_yield.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
@afifmohammed
afifmohammed / FreeIOMonad.cs
Created Jun 14, 2018 — forked from dadhi/FreeIOMonad.cs
Example of Free IO monad in pure C# with separated re-usable monad implementation
View FreeIOMonad.cs
/*
Modified from the original https://gist.github.com/louthy/524fbe8965d3a2aae1b576cdd8e971e4
- removed dependency on [language-ext](https://github.com/louthy/language-ext)
- separated monadic boilerplate, so you may concentrate on describing the operations and interpretation of the program
- removed `IO<A>.Faulted` to simplify the examples. It can be added back in straightforward manner.
Useful links:
- [John DeGoes: Beyond Free Monads - λC Winter Retreat 2017](https://www.youtube.com/watch?v=A-lmrvsUi2Y)
- [Free and tagless compared - how not to commit to a monad too early](https://softwaremill.com/free-tagless-compared-how-not-to-commit-to-monad-too-early)
View CSharp Free Monad.cs
//
// See https://github.com/louthy/language-ext
//
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using LanguageExt;
using static LanguageExt.Prelude;
View AggregateCorrelations.cs
void Main()
{
var events = new Event[]
{
new ItemAddedToCart(lead:"1", cart:"2", product:"44", title:"products/44/title/iphone-6s", when:DateTimeOffset.Now),
new ItemAddedToCart(lead:"1", cart:"2", product:"4", title:"products/4/title/iphone-5-SE", when:DateTimeOffset.Now),
new ItemRemovedFromCart(lead:"1", cart:"2", product:"44", when:DateTimeOffset.Now),
new OrderPlaced(customer:"1", order:"2", when:DateTimeOffset.Now.AddSeconds(123)),
new ItemShipped(order:"2", sku:"4", trackingid:"orders/2/skus/4/track/12", when:DateTimeOffset.Now.AddMinutes(33)),
new ItemAddedToCart(lead:"12", cart:"22", product:"42", title:"products/42/title/iphone-6s-plus", when:DateTimeOffset.Now.AddSeconds(12)),
View reader.cs
void Main()
{
var id = new Id();
Func<Id, Customer> customerById = x => new Customer();
Func<Criteria, CreditHistory> creditHistoryByCriteria = x => new CreditHistory();
Func<Report, Unit> print = x => new Unit();
var history = GetCustomer(id)
.Map(GetCustomerCreditHistory)
.Uncurry()
View parenting.md

Some Tips for Raising Muslim Children by Mufti Ismail Menk

  1. Praise your child, even if they get 4/10 in an exam, praise your child in front of others.

  2. Never make your child feel that he or she is useless. Never favour one child over the other.

  3. Every time you speak with your children, speak with respect, say “Jazakallahu khair ”, etc. Don’t use slang such as ‘gimme’, instead say ‘please give me’; use clear words, be polite and never swear.

  4. You need to bear in mind when your child is young that he or she is just a child, don’t take away their playing time by treating them like adults. If you do this, they will rebel in life.

@afifmohammed
afifmohammed / AsyncMonad.cs
Created Feb 13, 2017 — forked from hodzanassredin/AsyncMonad.cs
tutorial2 finished monad transformer
View AsyncMonad.cs
using System;
using System.Threading.Tasks;
namespace GenericMonad
{
public class Async
{
Async ()
{
@afifmohammed
afifmohammed / ReaderMonad.cs
Last active Jan 24, 2017 — forked from vmarquez/ReaderMonad.cs
This is an example of using the Reader Monad for Dependency Injection using LINQ in C#. I learned about this from Tony Morris and Rúnar Bjarnason's video here: http://www.youtube.com/watch?v=ECPGTUa1WAI To figure out the (slightly weird) SelectMany peculiarities I found http://mikehadlow.blogspot.com/2011/01/monads-in-c-4-linq-loves-monads.html
View ReaderMonad.cs
public static class ReaderMonadExt
{
public static Func<T, C> SelectMany<T, A, B, C>(this Func<T, A> t_a, Func<A, Func<T, B>> a_t_b, Func<A, B, C> ab_c)
{
return t =>
{
var a = t_a(t);
return ab_c(a, a_t_b(a)(t));
};
}
View Funcs.cs
using System;
namespace Funcs {
public static class Funcs {
public static Func<A, C> Select<A, B, C>(this Func<A, B> f, Func<B, C> g) {
return a => g(f(a));
}
public static Func<C, B> SelectMany<A, B, C>(this Func<C, A> f, Func<A, Func<C, B>> g) {
return a => g(f(a))(a);
@afifmohammed
afifmohammed / PureIO.cs
Created Apr 20, 2016 — forked from tonymorris/PureIO.cs
A demonstration of pure-functional I/O using the free monad in C#
View PureIO.cs
using System;
namespace PureIO {
/*
C# does not have proper sum types. They must be emulated.
This data type is one of 4 possible values:
- WriteOut, being a pair of a string and A
- WriteErr, being a pair of a string and A
- readLine, being a function from string to A
You can’t perform that action at this time.