Skip to content

Instantly share code, notes, and snippets.

View Masynchin's full-sized avatar

Max Smirnov Masynchin

View GitHub Profile
@friedbrice
friedbrice / BeginnerArgs.hs
Last active July 28, 2023 10:26
Haskell Command-line Arguments (scroll down for prose).
import System.Environment (getArgs)
myApp :: [String] -> IO ()
myApp args =
case args of
[name] -> putStrLn ("Top of the morning to you, " ++ name)
_ -> putStrLn "I only know how to use one argument D:"
main :: IO ()
main = do
@SegFaultAX
SegFaultAX / io.py
Created December 18, 2018 03:03
Simple IO monad [Python]
#!/usr/bin/env python
import functools
import typing as ty
from dataclasses import dataclass
A = ty.TypeVar("A")
B = ty.TypeVar("B")
@SegFaultAX
SegFaultAX / free.py
Created December 17, 2018 08:48
Simple Free Monad [Python]
import dataclasses as dc
import typing as ty
import inspect
import functools
S = ty.TypeVar("S")
A = ty.TypeVar("A")
B = ty.TypeVar("B")
@dc.dataclass(frozen=True)
@dsebban
dsebban / fs2-pull.md
Last active January 3, 2025 04:14
Understanding fs2 `Pull`

Undertsanding the Pull type from fs2

From the scaladocs

class Stream[+F[_], +O] extends AnyVal
  • A stream producing output of type O
  • May evaluate F effects.
@fschutt
fschutt / Rust.sublime-color-scheme
Created June 15, 2018 16:17
Rust Sublime Color Scheme
{
"name": "Rust color scheme",
"rules": [
/* --- grey items --- */
{
"scope": "comment",
"foreground": "color(var(black) blend(#fff 50%))",
},
/* --- red items --- */
{
@Daenyth
Daenyth / Pull.md
Last active December 8, 2024 00:27
Designing an fs2 `Pull` from scratch

The problem

I have some data which has adjacent entries that I want to group together and perform actions on. I know roughly that fs2.Pull can be used to "step" through a stream and do more complicated logic than the built in combinators allow. I don't know how to write one though!

In the end we should have something like

def combineAdjacent[F[_], A](
 shouldCombine: (A, A) => Boolean,
@Daenyth
Daenyth / MonadAndFs2Ops.md
Last active June 25, 2024 13:04
Cheat sheet for common cats monad and fs2 operation shapes
Operation Input Result Notes
map F[A] , A => B F[B] Functor
apply F[A] , F[A => B] F[B] Applicative
(fa, fb, ...).mapN (F[A], F[B], ...) , (A, B, ...) => C F[C] Applicative
(fa, fb, ...).tupled (F[A], F[B], ...) F[(A, B, ...)] Applicative
flatMap F[A] , A => F[B] F[B] Monad
traverse F[A] , A => G[B] G[F[A]] Traversable; fa.traverse(f) == fa.map(f).sequence; "foreach with effects"
sequence F[G[A]] G[F[A]] Same as fga.traverse(identity)
attempt F[A] F[Either[E, A]] Given ApplicativeError[F, E]
@jmlsf
jmlsf / js-in-cljs.md
Last active January 25, 2024 23:15
Using JavaScript modules in ClojureScript

Using JavaScript Libraries from ClojureScript

Using JavaScript libraries from ClojureScript involves two distinct concerns:

  1. Packaging the code and delivering it to the browser
  2. Making ClojureScript code that accesses JavaScript libraries safe for advanced optimization

Right now, the only single tool that solves these probems reliably, optimally, and with minimal configuration is shadow-cljs, and so that is what I favor. In paricular, shadow-cljs lets you install npm modules using npm or yarn and uses the resulting package.json to bundle external dependencies. Below I describe why, what alternatives there are, and what solutions I disfavor at this time.

Packaging and Delivering Code

@cscalfani
cscalfani / CompositionWithMultipleParameters.md
Created December 5, 2017 22:29
Functional Composition with Multiple Parameters in Haskell

Functional Composition with Multiple Parameters in Haskell

In the past, I've written composition functions in both Elm and Haskell that take multiple parameters for the leftmost function, i.e. the function that gets applied first.

(All examples here are in Haskell)

Here was my Haskell implemenation (stolen from the web):

compose2 :: (c -> d) -> (a -> b -> c) -> a -> b -> d
@ppisarczyk
ppisarczyk / Programming_Languages_Extensions.json
Last active April 29, 2025 15:35 — forked from aymen-mouelhi/languages.json
Programming Languages and their File Extensions
[
{
"name":"ABAP",
"type":"programming",
"extensions":[
".abap"
]
},
{
"name":"AGS Script",