This file contains 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
series :: Int -> [Int] | |
series n = go where go = n : (zipWith (+) go $ fmap mirror go) | |
mirror :: Int -> Int | |
mirror = undigits . digits | |
digits :: Int -> [Int] | |
digits = map (`mod` 10) . takeWhile (/= 0) . iterate (`div` 10) | |
undigits :: [Int] -> Int |
This file contains 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
package example | |
import cats._ | |
import cats.free._ | |
import cats.data._ | |
import cats.syntax.flatMap._ | |
import cats.effect.{LiftIO, IO} | |
object Example { | |
import functors._ |
This file contains 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 Control.Monad.State | |
-- first version | |
toh n = fst $ tohmoves n (n, 0, 0) | |
tohmoves :: Int -> (Int, Int, Int) -> (Int, (Int, Int, Int)) | |
tohmoves 1 (a, b, c) = (1, (a - 1, b, c + 1)) | |
tohmoves n (a, b, c) = | |
let (n', (a', c', b')) = tohmoves (n - 1) (a, c, b) | |
(n'', (a'', b'', c'')) = tohmoves 1 (a', b', c') |
This file contains 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
module Main where | |
-------------------------------------------------------------------------------- | |
import Data.HeytingAlgebra | |
import Prelude | |
import Data.Array (filter, any, (:), uncons) | |
import Data.Either (Either(..)) | |
import Data.Maybe (Maybe(..)) | |
import Data.Profunctor (class Profunctor, arr) | |
import Data.Profunctor.Choice (class Choice, left) |
This file contains 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
module Main where | |
import Prelude | |
import Data.Either (Either(..)) | |
import Data.Profunctor (class Profunctor, arr) | |
import Data.Profunctor.Choice (class Choice) | |
import Data.Profunctor.Strong (second) | |
import Data.Tuple (Tuple(..)) | |
-- State transformers |
This file contains 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
package humbug | |
package codecs | |
sealed abstract class Type[T] | |
case object TyBool extends Type[Boolean] | |
case object TyByte extends Type[Byte] | |
case object TyDouble extends Type[Double] | |
case object TyI16 extends Type[Short] | |
case object TyI32 extends Type[Int] | |
case object TyI64 extends Type[Long] |
This file contains 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
function stripMargin(sts, ...vals) { | |
let tts = sts[0]; | |
if( vals.length ) { | |
tts = sts.reduce((s, i) => s + vals[i], ''); | |
} | |
return tts.split('\n') | |
.map(s => s.trimLeft().startsWith('|') | |
? s.trimLeft().substr(1) | |
: s) |
This file contains 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
Object.defineProperty( | |
Object.prototype, | |
'copy', | |
{ value: function(spec) { | |
return Object.freeze(Object.assign({}, this, spec)); | |
} | |
} | |
); |
This file contains 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
data Tree a = Leaf a | Node a [Tree] | |
type Crumb a = (a, [Tree a], [Tree a]) | |
type Breadcrumbs a = [Crumb a] | |
type Zipper a = (Tree a, Breadcrumbs a) | |
goDown :: Zipper a -> Int -> Zipper a | |
goDown (Node el children, bs) n = let (head, nth:tail) = splitAt children n | |
in (nth, Crumb el head tail : bs) |
This file contains 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
--- We just read whatever comes from standard input and spit out its conversion result | |
main = interact louise | |
--- Our runner will just pipe the three components together: | |
louise :: String -> String | |
louise html = let result = parseHTML html >>= html2js >>= writeJS in | |
case result of | |
Right ok -> ok | |
Left nok -> "Error: " ++ nok | |
NewerOlder