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
| const Arr = (() => { | |
| const Nil = []; | |
| const Cons = head => rest => [head, ...rest]; | |
| const match = ({ Cons, Nil }) => a => | |
| a.length === 0 ? Nil : Cons(a[0])(a.slice(1)); | |
| return { Nil, Cons, match }; | |
| })(); | |
| const GenericList = ({ Cons, Nil, match }) => { |
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
| const { pipe, compose, map, encase, K, range, pow } = require("sanctuary"); | |
| const ret = compose; | |
| const repeat = n => x => map(K(x))(range(0, n)); | |
| const nify = n => pipe(repeat(n - 1)(ret)); | |
| const fail = () => { | |
| throw new Error(); | |
| }; | |
| // N-ifying encase |
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
| require("@babel/polyfill"); | |
| const { | |
| Fnctr, | |
| Arr, | |
| implement, | |
| Functor, | |
| Chain, | |
| Apply | |
| } = require("@masaeedu/fp"); | |
| const Cont = require("@masaeedu/fp/dist/instances/cont"); |
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
| const sillify = input => input | |
| .split("") | |
| .map((c, i) => i % 2 === 0 ? c.toLowerCase() : c.toUpperCase()) | |
| .reduce((p, c) => p + c) | |
| module.exports = { sillify } |
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
| const Cont = require("@masaeedu/fp/dist/instances/cont"); | |
| const S = require("sanctuary"); | |
| // > It is often said that callbacks do not compose. While this may | |
| // > be true, functions that *accept* callbacks compose extraordin- | |
| // > arily well. In fact, such functions, which I'll hereafter refer | |
| // > to as "continuations", form a monad, and a rather powerful and | |
| // > versatile monad at that. | |
| // > | |
| // > In this snippet, I'll try to demonstrate how the continuation |
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
| const fail = reason => { | |
| throw reason; | |
| }; | |
| const log = console.log; | |
| const Maybe = (() => { | |
| const k = Symbol(); | |
| // Algebra | |
| const Just = x => ({ [k]: x }); |
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
| {-# LANGUAGE NoMonomorphismRestriction, FlexibleContexts, FlexibleInstances, DeriveFunctor #-} | |
| import Data.Bool | |
| import Data.Functor | |
| import Data.Bifunctor | |
| import Data.Function ((&)) | |
| import Data.Semigroup | |
| import Control.Applicative | |
| import Control.Monad |
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 System.Threading.Tasks; | |
| namespace FPUtils | |
| { | |
| using static EnumerableUtils; | |
| using static DictUtils; | |
| using static TaskUtils; |
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
| // A simple pseudorandom number generator | |
| // http://indiegamr.com/generate-repeatable-random-numbers-in-js/ | |
| // :: type Seed = Int | |
| const PRNG = { | |
| // :: Seed -> Seed | |
| next: s => (s * 9301 + 49297) % 233280, | |
| // Generate a number between 0 and 1 | |
| // and increment the seed | |
| // :: Seed -> (Float, Seed) | |
| random: s_ => { |
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.Threading.Tasks; | |
| namespace tmp.zNpqzfT0PE | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| var job = ChangeForegroundColor(ConsoleColor.Blue) |