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
// MongoClient -- callbacks | |
var assert = require('assert') | |
var MongoClient = require('mongodb').MongoClient | |
MongoClient.connect('mongodb://localhost:27017/test', function(err,db) { | |
assert.equal(null,err) | |
console.log('connected') | |
db.collection('test').find().toArray(function(err,res) { | |
assert.equal(null,err) | |
console.log(res) | |
}) |
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
splitStr :: Eq a => [a] -> [a] -> [[a]] | |
splitStr sub str = split' sub str [] [] | |
where | |
split' _ [] subacc acc = reverse (reverse subacc:acc) | |
split' sub str subacc acc | |
| sub `isPrefixOf` str = split' sub (drop (length sub) str) [] (reverse subacc:acc) | |
| otherwise = split' sub (tail str) (head str:subacc) acc |
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
wordsWhen :: (Char -> Bool) -> String -> [String] | |
wordsWhen p s = case dropWhile p s of | |
"" -> [] | |
s' -> w : wordsWhen p s'' | |
where (w, s'') = break p s' |
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
chunks :: Int -> [a] -> [[a]] | |
chunks _ [] = [] | |
chunks n xs = (fst c) : chunks n (snd c) | |
where c = splitAt n xs | |
chunks' :: Int -> [a] -> [[a]] | |
chunks' n = unfoldr (\b -> if null b then Nothing else Just (splitAt n b)) | |
chunks'' :: Int -> [a] -> [[a]] | |
chunks'' n = takeWhile (not.null) . unfoldr (Just . splitAt n) |
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
fold' :: (b->a->b) -> b -> [a] -> b | |
fold' f b [] = b | |
fold' f b (h:t) = fold' f (f b h) t | |
map' :: (a->b) -> [a] -> [b] | |
map' f lst = fold' (\b a -> b ++ [f a]) [] lst | |
map'' :: (a->b) -> [a] -> [b] | |
map'' f [] = [] | |
map'' f (h:t) = f h : map'' f t |
NewerOlder