Skip to content

Instantly share code, notes, and snippets.

Avatar

Victor Nawothnig dminuoso

View GitHub Profile
View graham.hs
module Graham where
import Data.List (sortBy)
import Data.Ord (comparing)
import Data.Monoid
data Direction = Left'
| Right'
| Straight'
deriving (Show)
View contt.hs
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)
View state.hs
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
View foo.rb
module M
X = 1
end
Object.include M
A = String
puts A::X
X = 23
View foo.js
const idIfEq = (a, b) => a === b ? a : null
moves.find((row) => row.reduce(idIfEq))
View foo.js
const composeP2 = (f, g) => (val) => g(val).then((next) => f(next));
const composeP = (...funcs) => funcs.reverse().reduce(composeP2);
View van_laarhoven_lens.rb
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)
View van_laarhoven_lens.rb
# 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
View foo.rb
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
View foo.rb
def self.writer_path(*args)
-> (paths,val, obj) {
obj.deep_dup.tap { |o| o.dig(*paths) = val }
}.curry[*args]
end
You can’t perform that action at this time.