This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Is based on the dual pointer technique where ´current´ iterates as usual, | |
/// but ´runner´ iterates until it hits the ´current´, and then ´current´ proceeds. | |
pub fn remove_duplicates<'a, T: Eq>(data: &'a mut Vec<T>) { | |
let mut current_index = 0; | |
while current_index < data.len() { | |
let mut runner_index = 0; | |
while runner_index < current_index { | |
if &data[runner_index] == &data[current_index] { | |
data.remove(current_index); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def kaiFold[A, B](stuff: Seq[A], initial: B)(predicate: (B, A) => B): B = { | |
@tailrec | |
def it(items: Seq[A], accumulator: B): B = { | |
if (items.length == 0) accumulator | |
else { | |
val nextAccumulator = predicate(accumulator, items.head) | |
it(items.tail, nextAccumulator) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This first Signal[A] impl. uses STM (Ref — transactional references). | |
class Signal[A](initial: A) { | |
type SignalListener = Function[A, Unit] | |
val value = Ref(initial) | |
val listeners = Ref(Seq[SignalListener]()) | |
def set(newValue: A): Unit = { | |
// Atomically change the value within a transaction, blocks the thread, but a not an issue since it's a simple operation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window.Resources> | |
... | |
<!--A Style that affects all TextBlocks--> | |
<Style TargetType="TextBlock"> | |
<Setter Property="HorizontalAlignment" Value="Center" /> | |
<Setter Property="FontFamily" Value="Comic Sans MS"/> |