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
| -- | recursion version | |
| map' :: (a -> b) -> [a] -> [b] | |
| map' _ [] = [] | |
| map' f (x:xs) = f x : map' f xs | |
| filter' :: (a -> Bool) -> [a] -> [a] | |
| filter' _ [] = [] | |
| filter' f (x:xs) | |
| | f x = x : (filter' f 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
| -- | すごいHaskell楽しく学ぼう版 | |
| -- replicate 2 . product . map (*3) $ zipWith max [1, 2] [4, 5] | |
| -- | |
| -- | オリジナルパイプ版(UNIXライク) | |
| -- zipWith max [1, 2] [4, 5] > (map (*3) | product | replicate 2) | |
| -- | |
| (|) :: (a -> b) -> (b -> c) -> (a -> c) | |
| g | f = \x -> f $ g x | |
| (>) :: a -> (a -> b) -> 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
| import UIKit | |
| import RxSwift | |
| import RxCocoa | |
| class ViewController: UIViewController { | |
| @IBOutlet weak var textView: UITextView! | |
| @IBOutlet weak var countLabel: UILabel! | |
| @IBOutlet weak var textView2: UITextView! |
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
| func time(title: String, execute: () -> ()) { | |
| let now = NSDate() | |
| execute() | |
| let interval = NSDate().timeIntervalSinceDate(now) | |
| print("\(title): \(interval)") | |
| } | |
| var s = Set<String>() | |
| (0..<1000).forEach{ s.insert(String($0)) } |
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
| -- CSVFormatter.hs | |
| {- | |
| Input: | |
| Name,Birthday,Height | |
| Suzukaze Aoba,2/2,149cm | |
| Ko Yagami,8/2,164cm | |
| Rin Toyama,12/3,158cm |
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
| // Definition | |
| extension Array { | |
| func reduceDictionary<Key: Hashable, Value>(extractKeyValue: Element -> (Key, Value)) -> [Key: Value] { | |
| return reduce([Key: Value]()) { | |
| var dictionary = $0.0 | |
| let (key, value) = extractKeyValue($0.1) | |
| dictionary[key] = value | |
| return dictionary | |
| } | |
| } |
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
| type Distance = Double | |
| data Position = Position Double Double deriving (Show) | |
| data Ship = Ship { position :: Position | |
| , firingRange :: Distance | |
| , unsafeRange :: Distance } deriving (Show) | |
| type Region = Position -> Bool |
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 stack | |
| -- stack --resolver lts-7.0 --install-ghc runghc --package turtle | |
| {-# LANGUAGE OverloadedStrings #-} | |
| import Data.Text (pack, unpack) | |
| import Turtle | |
| joinM :: (Monoid m) => m -> [m] -> m | |
| joinM separator = foldl1 (\a b -> a `mappend` separator `mappend` 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
| // Class and Struct memory allocation in Swift 3.0 | |
| func adr<T>(_ title: String, _ x: inout T) { | |
| withUnsafePointer(to: &x) { | |
| print(title, $0) | |
| } | |
| } | |
| class C0 {} | |
| class C1 { |