K

@kenbitanga

Ruby: Partition Array

Ruby
2 years ago
def partition(f, li, ys=[], zs=[]) return ys, zs if li.empty? x, *xs = li return partition(f, xs, [*ys, x], zs) if f.call(x) partition(f, xs, ys, [*zs, x]) end p partition(->(x){x%2==1}, [1,2,3,4,5,6])

JS: Partition Array

NodeJS
2 years ago
function partition(f, li, ys=[], zs=[]) { if (li.length === 0) return [ys, zs] const [x, ...xs] = li return (f(x)) ? partition(f, xs, [...ys, x], zs) : partition(f, xs, ys, [...zs, x]) } const [a, b] = partition(x => x%2==0, [0,1,2,

Python: Partition List

Python
2 years ago
def partition(f, li, ys=[], zs=[]): if len(li) == 0: return ys, zs x, *xs = li if f(x): return partition(f, xs, [*ys, x], zs) return partition(f, xs, ys, [*zs, x]) li = [1,2,3,4,5,6] print(partition(lambda x: x%2==1, li))

Haskell: Partition

Python
2 years ago
partition _ [] = ([], []) partition f (x:xs) = let (ys, zs) = partition f xs in if f x then (x:ys, zs) else (ys, x:zs) main = do let li = [0,1,2,3,4,5] print $ partition odd li

Haskell: Quicksort - Partition - Where

Python
2 years ago
qsort [] = [] qsort (p:xs) = (qsort lt) ++ [p] ++ (qsort gt) where (lt, gt) = partition' (\x -> x <= p) xs partition' _ [] = ([], []) partition' f (x:xs) | f x = (x:ys, zs) | otherwise = (ys, x:zs) where (ys, zs) = partition'

Python: Quicksort - Partition - Purely Functional

Python
2 years ago
def partition(li, f, a=[], b=[]): if len(li) == 0: return a, b x, *xs = li if f(x): return partition(xs, f, [*a, x], b) return partition(xs, f, a, [*b, x]) def qsort(li): if len(li) == 0: return [] p, *xs = li

Haskell: Quicksort - Partition - Where

Python
2 years ago
qsort [] = [] qsort (p:xs) = qsort lt ++ [p] ++ qsort gt where (lt, gt) = partition' ((>) p) xs partition' _ [] = ([], []) partition' f (x:xs) | f x = (x:accepted, rejected) | otherwise = (accepted, x:rejected) where (accepted, reject

Haskell: Quicksort - Partition - Let-In

Python
2 years ago
qsort [] = [] qsort (p:xs) = let (lt, gt) = partition' ((>) p) xs in qsort lt ++ [p] ++ qsort gt partition' _ [] = ([], []) partition' f (x:xs) = let (accepted, rejected) = partition' f xs in if f x then (x:accepted, rejected) else (

Haskell: Quicksort - Partition Function

Python
2 years ago
qsort [] = [] qsort (p:xs) = qsort lt ++ [p] ++ qsort gt where (lt, gt) = partition' (\x -> x <= p) xs -- lt = [x | x <- xs, x <= p] -- gt = [x | x <- xs, x > p] partition' _ [] = ([], []) partition' f (x:xs) | f x = ((x:accepted, re

Haskell: Quicksort - Partition Function

Python
2 years ago
qsort [] = [] qsort (x:xs) = qsort lt ++ [x] ++ qsort gt where (lt, gt) = partition' (\a -> a <= x) xs partition' _ [] = ([], []) partition' f (x:xs) | f x = ((x:accepted), rejected) | otherwise = (accepted, (x:rejected)) whe

Haskell: Filter List

Python
2 years ago
filter' :: (a -> Bool) -> [a] -> [a] filter' _ [] = [] filter' f (x:xs) | f x = x:rest | otherwise = rest where rest = filter' f xs

Python: Quicksort with Partition Function in Pure Functional Style

Python
2 years ago
def partition(tup, f, lt=(), gt=()): if len(tup) == 0: return lt, gt x, *xs = tup if f(x): return partition(xs, f, (x, *lt), gt) return partition(xs, f, lt, (x, *gt)) def qsort(tup): if len(tup) == 0: return () x, *

Python: Partition List - Iterative vs Recursive

Python
2 years ago
def partition_iterative(li, f): a, b = [], [] for x in li: if f(x): a.append(x) else: b.append(x) return a, b def partition_recursive(li, f):

JS: Quicksort in Haskell Style

NodeJS
2 years ago
function qsort(li, reverse=false) { if (li.length === 0) return [] const [x, ...xs] = li const ys = xs.filter(y => y <= x) const zs = xs.filter(z => z > x) return (reverse) ? [...qsort(zs, reverse), x, ...qsort(ys, rever

Python: Quicksort in Haskell Style

Python
2 years ago
def qsort(li, reverse=False): if len(li) == 0: return [] x, *xs = li ys = [a for a in xs if a <= x] zs = [b for b in xs if b > x] if reverse: return [*qsort(zs, reverse), x, *qsort(ys, reverse)] return [*qsort(ys, reverse), x, *qsort

Haskell: Quicksort

Python
2 years ago
qsort [] = [] qsort (x:xs) = (qsort ys) ++ [x] ++ (qsort zs) where ys = [a | a <- xs, a <= x] zs = [b | b <- xs, b > x] main = do putStrLn "Quicksort in Haskell" let unsorted = [2,4,1,3,5]

JS: Monads - Maybe Monad

NodeJS
2 years ago
function MONAD(modifier) { let prototype = Object.create(null) function unit(value) { let monad = Object.create(prototype) monad.bind = function (func, args) { return func(value, ...args) } if (typeof modifier === 'funct

JS: Monads - Ajax Monad

NodeJS
2 years ago
function MONAD() { let prototype = Object.create(null) function unit(value) { let monad = Object.create(prototype) monad.bind = function (func, args) { return func(value, ...args) } return monad }

JS: Monads - Lift

NodeJS
2 years ago
function MONAD() { let prototype = Object.create(null) function unit(value) { let monad = Object.create(prototype) monad.bind = function (func, args) { return func(value, ...args) } return monad }

JS: Monads - Identity Monad

NodeJS
2 years ago
function MONAD() { return function (value) { let monad = Object.create(null) monad.bind = function (func) { func(value) } return monad } }