Skip to content

Instantly share code, notes, and snippets.

Jaden Geller JadenGeller

Block or report user

Report or block JadenGeller

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
JadenGeller / Bag.swift
Created Mar 11, 2020
Add numbers in a bag that only exposes flatMap and count
View Bag.swift
public struct Bag<Member> {
private var members: [Member] = []
public var count: Int {
public func flatMap<NewMember>(_ transform: (Member) throws -> Bag<NewMember>) rethrows -> Bag<NewMember> {
Bag<NewMember>(members: try members.flatMap({ member in try transform(member).members }))
JadenGeller / Combine-Denormalization-Example.swift
Created Mar 7, 2020
Denormalizing automatically using Combine
View Combine-Denormalization-Example.swift
import Combine
extension Publishers {
typealias Pair<Upstream> = Publishers.Map<Publishers.Scan<Upstream, (Upstream.Output?, Upstream.Output?)>, (Upstream.Output?, Upstream.Output)> where Upstream: Publisher
extension Publisher {
func pair() -> Publishers.Pair<Self> {
scan((nil as Output?, nil as Output?), { previousPair, value in
(previousPair.1, value)
}).map({ pair in
JadenGeller / Combine-Pair-Sketchy.swift
Last active Mar 7, 2020
Pair Publisher in Combine
View Combine-Pair-Sketchy.swift
import Combine
extension Publisher {
func pair() -> Publishers.Pair<Self> {
Publishers.Pair(upstream: self)
extension Publishers {
class Pair<Upstream: Publisher>: Publisher {
JadenGeller / Set.hs
Last active Oct 30, 2019
Correct-by-composition set operations that cannot branch on ordering
View Set.hs
{-# LANGUAGE FlexibleInstances, UndecidableInstances, LambdaCase, DeriveFunctor, MonadComprehensions #-}
import qualified Prelude
import Prelude (Show, Num, Functor, Bool(..), not, Int, Maybe(..), Either(..), Eq, (==), (.), ($), const, otherwise)
import Control.Monad (MonadPlus, guard, when, unless, (>>=), fmap, mzero, mplus, return)
import qualified Data.Foldable
import Data.Foldable (Foldable)
import Data.Maybe (maybe, isJust)
import Data.Functor.Foldable (Fix)
JadenGeller /
Last active Jun 14, 2018
Rotate in place
def transpose_matrix(size, matrix):
for y in range(size):
for x in range(y):
matrix[y][x], matrix[x][y] = matrix[x][y], matrix[y][x]
def flip_y_matrix(size, matrix):
for y in range(size // 2):
flip_y = size - y - 1
for x in range(size):
matrix[x][y], matrix[x][flip_y] = matrix[x][flip_y], matrix[x][y]
JadenGeller / Constructive.idr
Created Apr 27, 2018
Are constructive programs better?
View Constructive.idr
import Data.List
import Data.List.Views
import Data.Vect
import Data.Vect.Views
%default total
-- Constructive
rotate : Vect len elem -> Vect len elem
JadenGeller /
Created Apr 2, 2018
Dynamic Type Checking
import inspect
def typeAsserting(f):
signature = inspect.signature(f)
def wrapper(*args, **kwargs):
bound_args = signature.bind(*args, **kwargs)
for name, parameter_value in bound_args.arguments.items():
expected_type = signature.parameters[name].annotation
JadenGeller /
Created Jan 24, 2018
A gross simple state machine
def join_quoted_strs(s):
r = ''
within_quotes = False
is_escaped = False
for c in s:
if within_quotes:
if is_escaped:
r += c
is_escaped = False
View TypeDictionary.swift
private struct TypeDescriptor: Hashable, CustomStringConvertible {
private let type: Any.Type
internal init(_ type: Any.Type) {
self.type = type
public var hashValue: Int {
return String(describing: type).hashValue
public static func ==(lhs: TypeDescriptor, rhs: TypeDescriptor) -> Bool {
View Advent1.swift
public struct RotatingIterator<Base: IteratorProtocol>: Sequence, IteratorProtocol {
private var skippedElements: [Base.Element] = []
private var base: Base
internal init(_ base: Base, count: Int) {
self.base = base
for _ in 0..<count {
guard let element = else { break }
You can’t perform that action at this time.