Skip to content

Instantly share code, notes, and snippets.

// Given this passes the type checker
type A = 'a' | 'b' | 'c';
type ShouldBeTrue = A extends string ? true : false;
const test: ShouldBeTrue = true;
// And these types
type FooBar<T = string | { [key: string]: FooBar<string> }> = T extends string
? Bar<T>
: {
[K in keyof T]: FooBar<T[K]>;
@cdmcmahon
cdmcmahon / pitch.md
Last active February 25, 2020 23:15
Swift Evolution Pitch: Implicit conversion of callable values to functions

Hello. This is just a pitch, no implementation. SE-0253: Callable values of user-defined nominal types called out the implicit conversion of callable values to functions in its future directions.

A value cannot be implicitly converted to a function when the destination function type matches the type of the  callAsFunction  method. Since  callAsFunction  methods are normal methods, you can refer to them directly via  .callAsFunction  and get a function.

>Implicit conversions impact the entire type system and require runtime support to work with dynamic casts; thus, further exploration is necessary for a formal proposal. This base proposal is self-contained; incremental proposals involving conversio

@cdmcmahon
cdmcmahon / PointFreeStateManagement.swift
Last active November 6, 2019 23:51
In the Point-Free series on application architecture and state management, they define a series of ways to compose reducers. Sometimes, however, it seems that the signature of reducers can complicate the signature of these different compositions. I found creating a typealias for reducers separated the concern of understanding the concept of redu…
// In the Point-Free series on application architecture and state management,
// they define a series of ways to compose reducers. Sometimes, however, it seems
// that the signature of reducers can complicate the signature of these different
// compositions. I found creating a typealias for reducers separated the concern of
// understanding the concept of reducers and understanding their higher order
// constructions, especially when starting to write my own.
// Adding a typealias for Reducer can make certain parts a bit more readable
typealias Reducer<Value, Action> = (inout Value, Action) -> Void
var nlWest = [
[119, "Los Angeles", null, null, null],
[137, "San Francisco", null, null, null],
[135, "San Diego", null, null, null],
[109, "Arizona", null, null, null],
[115, "Colorado", null, null, null]
];
var createEnterDataFunc = function(team){
return function(data) {
@cdmcmahon
cdmcmahon / sudoku_checker.cpp
Created March 27, 2013 23:24
This is a simple command line program written in C++ to solve and check solutions for sudoku puzzles. I programmed it for my Hacker School application. The sudoku is represented as an array of arrays.
//
// main.cpp
// sudoku_checker
//
// Created by Corey McMahon on 3/22/13.
// Copyright (c) 2013 Corey McMahon. All rights reserved.
//
#include <iostream>
using namespace std;