Skip to content

Instantly share code, notes, and snippets.

@BalmungSan
BalmungSan / monads.md
Created November 15, 2022 21:15
What is a Monad and why you shouldn't care

What is a Monad and why you shouldn't care

People trying to learn about FP will heard about the M word sooner than latter. Personally I believe that way sooner than what is required, and recommended; which is what makes folks to be confused about it.

This is my humble attempt to try to briefly explain the concept, while also arguing that you shouldn't really care too much about it. This all with the intention to make your FP journey more enjoyable 😄 — without further ado, let's start.

Motivation behind Monads

@Savelenko
Savelenko / Validation2.fs
Created June 14, 2022 08:29
Applicative validation with abstract static interface members
(*
The original applicative validation type is defined like this in FsToolkit.ErrorHandling:
*)
/// Validation<'a, 'err> is defined as Result<'a, 'err list> meaning you can use many of the functions found in the
/// Result module.
type Validation<'ok, 'error> = Result<'ok, List<'error>>
(*
We can abstract the `List` away by requiring any structure which supports concatenation, of which the list's (@) is an
@datakurre
datakurre / python-packages.nix
Last active October 14, 2022 04:52
"setup.nix" packaging example
# Generated by pip2nix 0.8.0.dev1
# See https://github.com/nix-community/pip2nix
{ pkgs, fetchurl, fetchgit, fetchhg }:
self: super: {
"Babel" = super.buildPythonPackage rec {
pname = "Babel";
version = "2.9.0";
src = fetchurl {
@Guevara-chan
Guevara-chan / rl_converter.coffee
Last active October 5, 2023 01:45
RayLib h2nim autoconverter
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
# RayLib h2nim autoconverter v0.05
# Developed in 2*20 by Guevara-chan
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
[fs, rl, http] = [require('fs'), require('readline'), require('https')] if process?
#.{ [Procedures]
sanity = (name, undes = /\*/g) ->
name = name.replace(undes, '')
if name in ['type', 'end', 'from', 'div', 'ptr'] then name + 'x' else name
@BalmungSan
BalmungSan / Streaming.scala
Created June 25, 2019 21:15
10 code snippets to introducing cats.effect.IO & fs2.Stream
// IO: A Monad for side-effects.
import $ivy.`org.typelevel::cats-effect:1.3.1`
import cats.effect.IO
import scala.concurrent.ExecutionContext
implicit val IOTimer = IO.timer(ExecutionContext.global)
implicit val IOShift = IO.contextShift(ExecutionContext.global)
// ----------------------------------------------
@swlaschin
swlaschin / effective-fsharp.md
Last active March 8, 2024 03:10
Effective F#, tips and tricks

Architecture

  • Use Onion architecture

    • Dependencies go inwards. That is, the Core domain doesn't know about outside layers
  • Use pipeline model to implement workflows/use-cases/stories

    • Business logic makes decisions
    • IO does storage with minimal logic
    • Keep Business logic and IO separate
  • Keep IO at edges

@honewatson
honewatson / concepts.nim
Last active March 24, 2024 23:58
Nim Concepts Example - Concepts are Generics
import strutils
type
Dispatch = enum
Reveal
IKind = enum
Human, NonHuman
ObIkind = ref object of RootObj
kind*: IKind
Person = object of ObIkind