Skip to content

Instantly share code, notes, and snippets.

@aaronlevin
aaronlevin / complicated-paren-checker.hs
Last active June 24, 2016 16:57
Adventures in Point-Free, Arrowized Absurdity
-- | check for parens in a string, exiting early if the left paren count is -1. Fully point-free and
-- arrow-fied
-- It works as follows:
-- 1. use a monadic fold (foldM) with the Either monad to exit early
-- 2. take a list of methods that test if the count is -1, or the paren is '(', or the paren is ')'
-- 3. zip the list with another list that looks at the booleans and decides what functions they should
-- result in. if there are no parens, the functions just add 0 to the count
-- 4. sequence the monad actions (this will exit early if there is a Left present)
-- 5. fold over the functions in the Right branch with function composition
-- 6. at this piont we just want to apply the the resulting function in the Right branch to the current
@davidallsopp
davidallsopp / PropertyTests.scala
Last active September 16, 2020 14:07
Examples of writing mixed unit/property-based (ScalaTest with ScalaCheck) tests. Includes tables and generators as well as 'traditional' tests.
/**
* Examples of writing mixed unit/property-based (ScalaCheck) tests.
*
* Includes tables and generators as well as 'traditional' tests.
*
* @see http://www.scalatest.org/user_guide/selecting_a_style
* @see http://www.scalatest.org/user_guide/property_based_testing
*/
import org.scalatest._
@swannodette
swannodette / core.cljs
Created September 20, 2013 16:23
The fact this won't type check is unbelievably cool
(ns typed-play.core
(:require-macros [cljs.core.typed :as t])
(:require [cljs.core.typed :as t]))
(t/ann my-identity (All [x] (Fn [x -> x])))
(defn my-identity [x]
(if (number? x)
(inc x)
x))