Skip to content

Instantly share code, notes, and snippets.

@EDmitry
EDmitry / extractMinBy.hs
Created March 17, 2015 19:06
extract minimum from the list in O(N)
extractMinBy :: (a -> a -> Ordering) -> [a] -> (a, [a])
extractMinBy f (x:xs) = extractMinBy' f [x] xs (x, xs)
extractMinBy' :: (a -> a -> Ordering) -> [a] -> [a] -> (a, [a]) -> (a, [a])
extractMinBy' f left [] r = r
extractMinBy' f left (r:right) z@(x, xs) = extractMinBy' f (left ++ [r]) right newResult
where newResult = if f r x == LT then (r, left ++ right) else z
import Data.List (inits)
rest :: String -> String -> [(Char, String)]
rest [] _ = []
rest (x:xs) ys = (x, xs ++ ys) : rest xs (x:ys)
permutations :: String -> [String]
permutations [x] = [[x]]
permutations xs = do (x, xs) <- rest xs ""

Keybase proof

I hereby claim:

  • I am edmitry on github.
  • I am dgorbik (https://keybase.io/dgorbik) on keybase.
  • I have a public key whose fingerprint is 5A7C 885B 066C F5C5 8CCA 3472 6830 80B1 D4E2 5BEB

To claim this, I am signing this object:

//: Playground - noun: a place where people can play
import UIKit
protocol Incable {
func inc () -> Incable
}
class DoubleWrapper : Incable {
let number: Double