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
| trait Functor[F[_]] { | |
| def fmap[A, B](f: A => B): F[A] => F[B] | |
| } | |
| trait Extend[F[_]] extends Functor[F] { | |
| // coflatmap | |
| def extend[A, B](f: F[A] => B): F[A] => F[B] | |
| } | |
| trait Comonad[F[_]] extends Extend[F] { |
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
| import scalaz.WriterT | |
| import scalaz.NonEmptyList | |
| import scalaz.syntax.id._ | |
| import scalaz.std.option._ | |
| import scalaz.syntax.std.option._ | |
| type OptionLogger[A] = WriterT[Option, NonEmptyList[String], A] | |
| val two: OptionLogger[Int] = WriterT.put(2.some)("The number two".wrapNel) |
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
| function curry(f) { | |
| return function(x) { | |
| var g = f.bind(this, x); | |
| if(g.length == 0) return g(); | |
| if(arguments.length > 1) return curry(g).apply(this, [].slice.call(arguments, 1)); | |
| return curry(g); | |
| }; | |
| } | |
| var sum = curry(function(x, y) { |
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
| /** | |
| * We can use the Scala type system (with help from Miles Sabin's Shapeless | |
| * library) to solve the bank account number validation problem in the second | |
| * user story of the KataBankOCR kata on Coding Dojo: | |
| * | |
| * http://codingdojo.org/cgi-bin/wiki.pl?KataBankOCR | |
| * | |
| * By Travis Brown in response to a question by Paul Snively on the Shapeless | |
| * Dev mailing list: | |
| * |
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
| // Inspired by http://dave.fayr.am/posts/2012-10-4-finding-fizzbuzz.html | |
| object FizzBuzz extends App { | |
| import scalaz._ | |
| import Scalaz._ | |
| def fizzbuzz(i: Int) = ((i % 3 == 0) option "fizz") |+| ((i % 5 == 0) option "buzz") | i.shows | |
| for (i <- 1 to 100) {println(i + " " + fizzbuzz(i))} | |
| } |
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
| module Main where | |
| import Control.Applicative ((<*>)) | |
| import Data.Semigroup ((<>)) -- http://hackage.haskell.org/package/semigroups | |
| import Data.Maybe (fromMaybe, listToMaybe, maybe) | |
| import System.Environment (getArgs) | |
| import Data.Lens.Partial.Common(getorPL, headLens) -- http://hackage.haskell.org/package/data-lens | |
| fizzbuzz :: | |
| Integral a => |
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
| Moved to https://github.com/tonymorris/type-class |
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
| case class T() // your data type that you want to "implicitly" thread through | |
| case class TReader[+A](run: T => A) { | |
| def map[B](f: A => B): TReader[B] = | |
| sys.error("VFJlYWRlcihmIGNvbXBvc2UgcnVuKQ==") | |
| def flatMap[B](f: A => TReader[B]): TReader[B] = | |
| sys.error("VFJlYWRlcih0ID0+IGYocnVuKHQpKSBydW4gdCk=") | |
| def &&&[B](x: TReader[B]): TReader[(A, B)] = |
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
| (use '[clojure.core.logic]) | |
| (require '[clojure.core.logic.fd :as fd]) | |
| (defn simple [] | |
| (run* [x y] | |
| (fd/in x y (fd/interval 0 9)) | |
| (fd/eq | |
| (= (+ x y) 9) | |
| (= (+ (* 4 x) (* 2 y)) 24)))) |
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
| -- THE SEARCH CONTINUES | |
| data GenericThing = SpecificThing Char | |
| | DifferentSpecificThing Double | |
| | AnotherSpecificThing String | |
| | YetAnotherDifferentSpecificThing Integer | |
| foo :: [GenericThing] -> GenericThing | |
| foo [] = return $ AnotherSpecificThing "" | |
| foo [SpecificThing one] = -- do something |
OlderNewer