Skip to content

Instantly share code, notes, and snippets.

View svarlet's full-sized avatar
🤓

Sébastien Varlet svarlet

🤓
View GitHub Profile
@svarlet
svarlet / main.dart
Last active January 11, 2022 10:39
map.at
// Couldn't wrap my head around the proper use of List.fold or List.reduce, especially
// with the type system getting in the way. But here is a proper implementation that
// is recursive.
// Dart, like many other languages does not handle recursion very well (it doesn't
// have "Tail Call Optimization") so it's not recommended to use this if we recurse
// many times. It's hard to put an exact number to "many" though. In the dart VM it may
// be 15 times, or a thousand, and in JS I would bet it's 15.
// In any case, this extension method is syntaxic sugar for code like m['x']['y']['z']
// which is 3 recursions, so I doubt we'll ever get to even 10 recursions :)
extension NavigableMap on Map<String, dynamic> {
import 'package:test/test.dart';
import 'package:mocktail/mocktail.dart';
class Demo {
void doSomething(int i) {
i + i;
}
}
class DemoDouble extends Mock implements Demo {}
@svarlet
svarlet / controller.ex
Created June 17, 2019 15:55
Purely functional Clean architecture in elixir?
# I haven't actually written this controller yet, I'm adding one for illustration purposes.
defmodule Controller do
def list_products(connection, _params) do
products = connection.private.products_gateway.all() # no better way to inject stuff into a controller in elixir/phoenix :(
purchasable_products = Usecases.Shopper.ListProducts.list_products(products, Timex.now())
send_resp(connection, 200, purchasable_products)
end
end
module MouseParticle where
import Graphics.Element exposing (..)
import Graphics.Collage exposing (..)
import Color exposing (..)
import Mouse
import Window
import Time
------------------------------------------------------ MODEL