In this article I’ll tell you about my pure functional library for Software Transactional Memory (STM)
that I’ve built in C++. I adopted some advanced functional programming concepts that make it composable and convenient to use. Its implementation is rather small and robust, which differentiates the library from competitors. Let’s discuss what STM is and how to use it.
import { of, Stream, Scheduler, Sink, Source } from 'most' | |
import { curry2, CurriedFunction2 } from '@most/prelude' | |
class ThreadSource<T, R> implements Source<R> { | |
constructor (private fn: (a1: T) => void, private arg: T) { | |
} | |
run (sink: Sink<R>, scheduler: Scheduler) { | |
const fnContextStr = `(${this.fn.toString()})(${JSON.stringify(this.arg)})` |
/** | |
* Returns SHA-256 hash from supplied message. | |
* | |
* @param {String} message. | |
* @returns {String} hash as hex string. | |
* | |
* @example | |
* sha256('abc').then(hash => console.log(hash)); | |
* const hash = await sha256('abc'); | |
*/ |
All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.
Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.
elem.offsetLeft
,elem.offsetTop
,elem.offsetWidth
,elem.offsetHeight
,elem.offsetParent
Functional programming gets a bad wrap about being too hard for mere mortals to comprehend. This is nonsense. The concepts are actually quite simple to grasp.
The jargon is the hardest part. A lot of that vocabulary comes from a specialized field of mathematical study called category theory (with a liberal sprinkling of type theory and abstract algebra). This sounds a lot scarier than it is. You can do this!
All examples using ES6 syntax. wrap (foo) => bar
means:
function wrap (foo) {
Recommendations of unit types per media type:
Media | Recommended | Occasional use | Infrequent use | Not recommended |
---|---|---|---|---|
Screen | em, rem, % | px | ch, ex, vw, vh, vmin, vmax | cm, mm, in, pt, pc |
em, rem, % | cm, mm, in, pt, pc | ch, ex | px, vw, vh, vmin, vmax |
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
namespace SuffixTreeAlgorithm | |
{ | |
public class SuffixTree | |
{ |
/* | |
* This work is free. You can redistribute it and/or modify it under the | |
* terms of the Do What The Fuck You Want To Public License, Version 2, | |
* as published by Sam Hocevar. See the COPYING file for more details. | |
*/ | |
/* | |
* Easing Functions - inspired from http://gizma.com/easing/ | |
* only considering the t value for the range [0, 1] => [0, 1] | |
*/ | |
EasingFunctions = { |