Skip to content

Instantly share code, notes, and snippets.

@mwyrebski
mwyrebski / sample_fsharp_notebook.ipynb
Created March 31, 2023 14:00
Sample notebook running on the F# kernel.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mwyrebski
mwyrebski / domain-logic.md
Created February 23, 2023 18:52
On domain logic in microservices

On domain logic in microservices

A bunch of notes and observations on working and designing microservices. There are not many assumptions in the text except the perspective of functional programming (F# in this case).

Commands

  1. Commands trigger workflows.
  2. Workflows are the keys of business logic. They glue together I/O reads with functions that manipulate the domain objects on which I/O writes are performed afterwards.
    • The reason they can accept other functions (dependencies) means they can use mocked domain types.
  • Domain types should be strongly typed. Raw strings, bools, or ints should prohibited. DateTime can be too vague in some cases when domain logic only allows dates in the future.
@mwyrebski
mwyrebski / multi-mapping.md
Created February 11, 2021 08:30
Results multimapping a.k.a master-detail in F#

Results multimapping a.k.a master-detail in F#

Let's consider how we can query for the relational data given by these sample types:

Company
- Id
- Name
- Country
@mwyrebski
mwyrebski / NugetVersions.md
Last active June 26, 2020 08:09
Get versions of NuGet packages in repositories

Get versions of NuGet packages across all repositories using ripgrep.

Switch to the directory with the projects

cd ~/projects_dir

Pull changes for all repositories

find -name .git -type d -prune | xargs -t -I {} git -C {}/.. pull
@mwyrebski
mwyrebski / RgbDU.fsx
Created November 28, 2019 08:21
Enumerating through Cases of Discriminated Union in F#
//
// Example of enumerating through Cases of Discriminated Unions.
//
type Rgb =
| R
| G
| B
let colorText c =
@mwyrebski
mwyrebski / RgbEnum.fsx
Created November 27, 2019 23:06
Using enums and enumerating through enum values in F#.
//
// Example of using enums and enumerating through their values.
//
type RgbEnum =
| R = 0
| G = 1
| B = 2
let colorText e =
@mwyrebski
mwyrebski / paged.fs
Created November 19, 2019 19:44
Simple implementation of pagination function
module Seq =
/// Skips given count from source or returns empty sequence if skip is beyond the limits.
let safeSkip count source =
source
|> Seq.indexed
|> Seq.skipWhile (fun (i, _) -> i < count)
|> Seq.map snd
/// Takes given count from source or returns empty sequence. An alias for the `truncate`.
@mwyrebski
mwyrebski / FluentMessageProcessor.csproj
Last active June 12, 2019 21:03
Example of Message Processor with fluent configuration
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="2.2.0" />
</ItemGroup>
@mwyrebski
mwyrebski / ValidateNullSeq.fsx
Last active June 5, 2019 08:27
[F#] Sequences validation demo
// Short demonstration of sequences validation in F#.
// Sequences, unlike Lists allow null values. Assuming that valid input is a
// non-empty collection, we have to validate against nulls when using
// sequences as inputs (assuming nulls can be provided to our functions).
// Let's assume each function returns Result type which can be either
// Error with "Invalid input" message or Ok with processed values as list.
// ------------------------------------------------------------
@mwyrebski
mwyrebski / resophnotes.json
Created March 22, 2019 19:19
ResophNotes 1.7.0 (https://resoph.com) app manifest (install definition) for scoop (https://scoop.sh).
{
"version": "1.7.0",
"description": "Quick Notes on Windows",
"homepage": "https://resoph.com/ResophNotes",
"license": {
"identifier": "Freeware",
"url": "https://resoph.com/ResophNotes/Terms_of_Use.html"
},
"extract_dir": "ResophNotes",
"architecture": {