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
class Maybe | |
def self.empty | |
Maybe.new nil | |
end | |
def initialize(value) | |
@value = value | |
end | |
def bind(f) | |
@value.nil? ? self : f.call(@value) | |
end |
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
// See also: http://davesquared.net/2012/12/lazy-monad-csharp.html | |
public static class LazyExtensions | |
{ | |
public static Lazy<TResult> Select<T, TResult>(this Lazy<T> value, Func<T, TResult> selector) | |
{ | |
return new Lazy<TResult>(() => selector(value.Value)); | |
} | |
public static Lazy<TResult> SelectMany<T, TResult>(this Lazy<T> value, Func<T, Lazy<TResult>> selector) |
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
error FS0193: internal error: Value cannot be null. | |
Parameter name: con |
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
[Test] | |
public void TEST() | |
{ | |
var results = FirstResults().Concat(GetResults()); | |
Console.WriteLine("results created"); | |
Console.WriteLine("get first"); | |
results.First(); | |
Console.WriteLine("get last"); |
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 Control.Arrow ((>>>)) | |
import Data.List.Zipper | |
import Data.Maybe | |
{- ref: | |
- http://www.reddit.com/r/dailyprogrammer/comments/12qi5b/1162012_challenge_111_easy_star_delete/ | |
- -} | |
starDelete' :: String -> String | |
starDelete' [] = [] |
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
[Test] | |
public void ShouldNotReturnNullWebServiceResponse() | |
{ | |
var iv_client = Substitute.For<Client>(); | |
iv_client.GetValuation("G1|12345", 10000, 2008, "08").Returns(new WebServiceResponse() | |
{ | |
Result = false, | |
ErrorEnum = IdResponseCode.NoDataFound | |
}); |
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
runKoan :: Koan -> IO Bool | |
runUntilFail :: [Koan] -> IO () | |
runUntilFail [] = return () | |
runUntilFail (x:xs) = do | |
continue <- runKoan x | |
when continue $ runUntilFail xs |
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
randomMonth :: (RandomGen g) => State g String | |
randomMonth = | |
let monthNames = [ "January", "February", "March" | |
, "April", "May", "June" | |
, "July", "August", "September" | |
, "October", "November", "December" | |
] | |
in (monthNames !!) <$> randomNumber (1,11) | |
randomNumber :: (RandomGen g) => (Int,Int) -> State g Int |
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 Control.Monad.State | |
import System.Random | |
type Field = String | |
replaceField :: String -> Field -> Field | |
replaceField newContent field = | |
let fieldName = takeWhile (/=':') field | |
in fieldName ++ ": " ++ newContent |
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
randomChar :: (RandomGen g) => State g Char | |
randomChar = state $ randomR ('a','z') | |
randomStringWithLength :: (RandomGen g) => Int -> State g String | |
randomStringWithLength i = replicateM i randomChar | |
randomString :: (RandomGen g) => State g String | |
randomString = state $ \g -> | |
let (charsToGen, g') = randomR (1,10) g | |
in runState (randomStringWithLength charsToGen) g' |