Skip to content

Instantly share code, notes, and snippets.

View dminuoso's full-sized avatar

Victor Nawothnig dminuoso

View GitHub Profile
usages = lines
.map(&:split)
.group_by(&loginL)
.map(&toUsage)
.sort_by(&:trafficOut)
.reverse
def self.writer_path(*args)
-> (paths,val, obj) {
obj.deep_dup.tap { |o| o.dig(*paths) = val }
}.curry[*args]
end
@dminuoso
dminuoso / foo.rb
Last active November 6, 2017 08:36
class Hash
def self.setter(*args)
-> (paths, val, obj) {
obj.deep_dup.tap do |o|
*dir, final = paths
if dir.empty?
o.store(final, val)
else
o.dig(*dir).store(final, val)
end
# Identity functor that does not give any additional structure
Identity = Struct.new(:value) do
def fmap(func = nil, &blk)
f = func || blk;
Identity.new(f.call(self.value))
end
end
# Const Functor that preserves its content
Const = Struct.new(:value) do
@dminuoso
dminuoso / foo.js
Last active November 7, 2017 18:45
const composeP2 = (f, g) => (val) => g(val).then((next) => f(next));
const composeP = (...funcs) => funcs.reverse().reduce(composeP2);
Identity = Struct.new(:value) do
def fmap(*args)
-> (func) {
Identity.new(func.call(self.value))
}.curry[*args]
end
end
Const = Struct.new(:value) do
def fmap(*args)
const idIfEq = (a, b) => a === b ? a : null
moves.find((row) => row.reduce(idIfEq))
module M
X = 1
end
Object.include M
A = String
puts A::X
X = 23
combine1 :: (a -> a) -> State [a] ()
combine1 op = do
a <- pop
push $ op a
combine2 :: (a -> a -> a) -> State [a] ()
combine2 op = do
a <- pop
b <- pop
push op a b
@dminuoso
dminuoso / contt.hs
Last active December 8, 2017 18:14
module ContT where
import Control.Monad.Trans.Class
newtype ContT r m a = ContT { runContT :: (a -> m r) -> m r }
instance Functor (ContT r m) where
fmap f (ContT cv) = ContT $ \c ->
cv (c . f)