Skip to content

Instantly share code, notes, and snippets.

View jmgimeno's full-sized avatar

Juan Manuel Gimeno jmgimeno

View GitHub Profile
@johnynek
johnynek / sortmerge.scala
Last active October 14, 2022 10:32
merge sorted streams with fs2
import fs2.{Chunk, Stream, Pull}
import cats.collections.Heap
import cats.implicits._
object SortMerge {
def sortMerge[F[_], A: Ordering](streams: List[Stream[F, A]]): Stream[F, A] = {
implicit val ord: cats.Order[Stream.StepLeg[F, A]] =
new cats.Order[Stream.StepLeg[F, A]] {
val ordA = implicitly[Ordering[A]]
@ChrisPenner
ChrisPenner / Optics Cheatsheet.md
Last active April 21, 2025 12:45
Optics Cheatsheet
@dacr
dacr / index.md
Last active April 5, 2025 07:36
David's programming examples knowledge base / published by https://github.com/dacr/code-examples-manager #fecafeca-feca-feca-feca-fecafecafeca/3d5c87884060c3d7f6d0a83ab732c819503365eb

David's programming examples knowledge base

akka-pekko

@mmenestret
mmenestret / fp_taglessfinal_explanation.md
Last active February 7, 2025 19:55
FP and tagless final - Fabio Labella

Purity and pure FP

  • purity is a syntactical property of programs, more precisely defined as referential transparency: replacing an expression for its bound value doesn't change meaning (precise definition)
  • side effects are things that break referential transparency (precise definition)
  • There's no direct connection between the concepts of IO, State and so on, and side effects. Traditionally, these things are side effectful (break referential transparency), but you can have abstractions that are pure (don't break ref.trans.)
  • Due to the above, the term purely functional programming is not an oxymoron, it makes perfect sense.
  • In haskell style pure FP, type constructors and algebras are used to represent "things that would otherwise traditionally be side effects (break ref.trans.)". We call these F[_]s effects or computational contexts for brevity. You can see for yourself how this cannot be a precise definition (especially because they could also have kind higher than * -> *, even though most famous a
@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.
@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,
@davidkaste
davidkaste / roll.hs
Created April 12, 2018 10:46
Dice roll utility made in Haskell
-- roll.hs a dice rolling shell utility
-- David Castellà 'kaste' <[email protected]>
import Data.List.Split
import Data.List
import Data.Char
import System.Random
import Control.Monad
import Control.Arrow
import Options.Applicative
@rebcabin
rebcabin / CompositionsOfCompositions.txt
Last active December 14, 2019 01:25
Compositions of compositions in Haskell, pursuant to https://github.com/ekmett/lens/wiki/Derivation
In https://github.com/ekmett/lens/wiki/Derivation, we see some types for
composition of compositions: (.).(.), (.).(.).(.), and so on. Let's prove that
the type of (.).(.) is (a -> b) -> (c -> d -> a) -> c -> d -> b, as stated in
the site. We'll stick with prefix notation, meaning that we want the type of
(.)(.)(.).
Recall the type of composition. This should be intuitive:
(.) :: (b -> c) -> (a -> b) -> a -> c [1]
@gaga5lala
gaga5lala / restore_docker_image_tag.sh
Created November 7, 2017 02:04
Restore docker image tag from text file.
# 1. Backup image tags to text file.
# $ docker images --format "{{.Repository}}:{{.Tag}} {{.ID}}" > img_id.txt
#
# 2. Execute clean-docker-for-mac script
# $ bash clean-docker-for-mac.sh $(docker images --format "{{.ID}}" | xargs)
#
# source: https://gist.github.com/MrTrustor/e690ba75cefe844086f5e7da909b35ce#file-clean-docker-for-mac-sh
#
# 3. Execute this script to restore tags from text file.
@IGI-111
IGI-111 / category_theory.md
Last active September 12, 2023 19:32
"category theory for programmers" blog post series parsed into markdown and formatted in a pdf

Category Theory for Programmers: The Preface

Table of Contents

Part One