Skip to content

Instantly share code, notes, and snippets.

View CoditCompany's full-sized avatar
👋
You can find us on @CoditEU

Codit CoditCompany

👋
You can find us on @CoditEU
View GitHub Profile
// int -> Parser<'a, 'u> -> Parser<'a list, 'u>
let count n p =
match n with
| _ when n <= 0 -> preturn []
| _ -> sequence <| List.replicate n p
// Parser<('a -> 'b), 'u> -> Parser<'a, 'u> -> Parser<'b, 'u>
let apply fp xp =
pipe2 fp xp (fun f x -> f x)
// ('a -> Parser<'b, 'u>) -> 'a list -> Parser<'b list, 'u>
let traverse f list =
let (<*>) = apply
let retn = preturn
let cons head tail = head :: tail
// int -> Parser<'a, 'u> -> Parser<'a, 'u> list
let count n p =
List.replicate n p
// int -> Parser<'a, 'u> -> Parser<'a list, 'u>
let count n p =
match n with
| _ when n <= 0 -> preturn []
| _ ->
let tryTake xs =
match xs with
| _ when List.length xs >= n -> preturn <| List.take n xs
| _ -> fail <| sprintf "Expecting %i number of elements" n
let countAZ n = regex <| sprintf "[A-Z]{%i}" n
let count09 n = regex <| sprintf "[0-9]{%i}" n
@CoditCompany
CoditCompany / AzureFunction.cs
Last active August 31, 2017 09:17
Azure Funciton Proxies
#r "Newtonsoft.Json"
using System;
using System.Net;
using Newtonsoft.Json;
using System.Collections.Generic;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage request, int orderId, TraceWriter log)
{
log.Info($"Webhook was triggered!");
change
|> List.map valueOfCoin
|> List.sum
|> (fun change -> remain + change)
|> (fun actual -> expected = actual)
change
|> List.map valueOfCoin
|> List.sum
|> (+) remain
|> (=) expected
let bind f x = function
| Success x -> f x
| Failure errs -> Failure errs
let (>>=) x f = bind f x
let bind twoTrackFunction twoTrackInput = function
| Success result -> twoTrackFunction result
| Failure errors -> Failure errors
let (>>=) twoTrackInput twoTrackFunction =
bind twoTrackInput twoTrackFunction