This file contains 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
usages = lines | |
.map(&:split) | |
.group_by(&loginL) | |
.map(&toUsage) | |
.sort_by(&:trafficOut) | |
.reverse |
This file contains 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
def self.writer_path(*args) | |
-> (paths,val, obj) { | |
obj.deep_dup.tap { |o| o.dig(*paths) = val } | |
}.curry[*args] | |
end |
This file contains 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 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 |
This file contains 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
# 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 |
This file contains 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
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) |
This file contains 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
const composeP2 = (f, g) => (val) => g(val).then((next) => f(next)); | |
const composeP = (...funcs) => funcs.reverse().reduce(composeP2); |
This file contains 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
const idIfEq = (a, b) => a === b ? a : null | |
moves.find((row) => row.reduce(idIfEq)) |
This file contains 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
module M | |
X = 1 | |
end | |
Object.include M | |
A = String | |
puts A::X | |
X = 23 |
This file contains 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
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 |
This file contains 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
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) |