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 a() { return "hoge"; } | |
function b() { eeee eeee } // SyntaxError: Unexpected identifier | |
(5 <= 6) ? console.log(a()) : console.log(b()); | |
// (5 >= 6) ? console.log(a()) : console.log(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
function a() { return "hoge"; } | |
function b() { eeee } | |
(5 <= 6) ? console.log(a()) : console.log(b()); | |
// (5 >= 6) ? console.log(a()) : console.log(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 strict"; // この場合はグローバル | |
function a() { | |
"use strict"; // 関数スコープみたいなもの | |
}; | |
// use strictを二重に書いても問題はない | |
// 実装者が考えてくれという話 | |
// プログラムは書かれていなくてもいい |
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 strict"; // この場合はグローバル | |
function a() { | |
"use strict"; // 関数スコープみたいなもの | |
}; | |
// use strictを二重に書いても問題はない | |
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 Data.Monoid | |
import qualified Data.Foldable as F | |
data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show) | |
instance F.Foldable Tree where | |
foldMap f EmptyTree = mempty | |
foldMap f (Node x l r) = F.foldMap f l `mappend` | |
f x `mappend` | |
F.foldMap f r |
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 qualified Data.Foldable as F | |
main = do | |
print $ foldr (*) 1 [1,2,3] | |
print $ F.foldr (*) 1 [1,2,3] | |
print $ F.foldl (+) 2 (Just 9) | |
print $ F.foldr (||) False (Just True) |
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 Data.Monoid | |
main = do | |
print $ Nothing `mappend` Just "andy" | |
print $ Just LT `mappend` Nothing | |
print $ Just (Sum 3) `mappend` Just (Sum 4) | |
print $ getFirst $ First (Just 'a') `mappend` First (Just 'b') | |
print $ getFirst $ First Nothing `mappend` First (Just 'b') | |
print $ getFirst $ First (Just 'a') `mappend` First Nothing | |
print $ getFirst . mconcat . map First $ [Nothing, Just 9, Just 10] |
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 Data.Monoid | |
main = do | |
print $ Nothing `mappend` Just "andy" | |
print $ Just LT `mappend` Nothing | |
print $ Just (Sum 3) `mappend` Just (Sum 4) | |
print $ getFirst $ First (Just 'a') `mappend` First (Just 'b') | |
print $ getFirst $ First Nothing `mappend` First (Just 'b') | |
print $ getFirst $ First (Just 'a') `mappend` First Nothing | |
print $ getFirst . mconcat . map First $ [Nothing, Just 9, Just 10] |
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 Data.Monoid | |
main = do | |
print $ Nothing `mappend` Just "andy" | |
print $ Just LT `mappend` Nothing | |
print $ Just (Sum 3) `mappend` Just (Sum 4) | |
print $ getFirst $ First (Just 'a') `mappend` First (Just 'b') | |
print $ getFirst $ First Nothing `mappend` First (Just 'b') | |
print $ getFirst $ First (Just 'a') `mappend` First Nothing | |
print $ getFirst . mconcat . map First $ [Nothing, Just 9, Just 10] |
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 Data.Monoid | |
lengthCompare1 :: String -> String -> Ordering | |
lengthCompare1 x y = let a = length x `compare` length y | |
b = x `compare` y | |
in if a == EQ then b else a | |
lengthCompare2 :: String -> String -> Ordering | |
lengthCompare2 x y = (length x `compare` length y) `mappend` | |
(x `compare` y) |