Skip to content

Instantly share code, notes, and snippets.

@spencerwi
spencerwi / FoldMapAndFilter.clj
Last active May 16, 2020 03:30
Any place I have first-class functions and recursion, I can build foldLeft (reduce), with which I can build map and filter.
(defn fold_ [f initial [head & the-rest :as arr]]
(cond
(empty? arr) initial
:else (recur f (f initial head) the-rest)))
(defn map_ [f arr]
(let [applyF (fn [previous current] (conj previous (f current)))]
(fold_ applyF [] arr)))
(defn filter_ [predicate arr]
@Dorus
Dorus / Additional Rx Extension Methods
Last active October 15, 2016 21:27
RxExtensions.cs
public static class Extended {
public static IObservable<TSource> Amb<TSource>(this IObservable<IObservable<TSource>> source) {
return Observable.Create<TSource>(o => {
int first = -1;
return source.TakeWhile(_ => first == -1)
.Select((el, c) => el
.DoFirst(1, _ => Interlocked.CompareExchange(ref first, c, -1))
.TakeWhile(_ => first == c))
.Merge().Subscribe(o);
[user]
name = jnm2
email = [email protected]
[core]
pager = cat
autocrlf = true
editor = 'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin
[fetch]
prune = true
[alias]