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 Factorial where | |
factorial :: Integral a => a -> a | |
factorial 0 = 1 | |
factorial n = n * factorial (n - 1) | |
factorialSeq :: Integral a => [a] | |
factorialSeq = scanl (*) 1 [1..] |
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
λ> data Box a = Box a deriving (Show, Eq) | |
type Box :: * -> * | |
data Box a = ... | |
-- Functorの実装 | |
λ> :{ | |
λ| instance Functor Box where | |
λ| fmap f (Box x) = Box $ f x | |
λ| :} | |
-- Applicativeの実装 | |
λ> :{ |
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
(ns money | |
(:refer-clojure :exclude [+]) | |
(:require | |
[clojure.spec.alpha :as s]) | |
(:import | |
(java.util | |
Currency))) | |
(s/def ::amount nat-int?) | |
(s/def ::currency #(instance? Currency %)) |
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 MyPrelude where | |
import Prelude hiding (filter, foldl, foldr, map, reverse) | |
foldLeft :: (b -> a -> b) -> b -> [a] -> b | |
foldLeft _ acc [] = acc | |
foldLeft f acc (x:xs) = foldLeft f (f acc x) xs | |
reverse' :: [a] -> [a] | |
reverse' = foldLeft (flip (:)) [] |
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
scala> enum ShippingCategory: | |
| case UsLocalState, UsRemoteState, International | |
| | |
// defined class ShippingCategory | |
scala> object Address: | |
| class AddressInfo(val country: String, val state: String) | |
| | |
| def apply(country: String, state: String) = AddressInfo(country, state) | |
| |
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
#!/usr/bin/env bash | |
# npm install -g reveal-md | |
reveal-md tdd-with-rdd.md --theme night --highlight-theme monokai-sublime -w $@ |
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
(ns clj-tdd-with-rdd.core | |
(:require | |
[clojure.spec.alpha :as s] | |
[clojure.string :as str])) | |
(s/fdef fizzbuzz | |
:args (s/cat :n pos-int?) | |
:ret string?) | |
(defn fizzbuzz [n] |
NewerOlder