This file contains hidden or 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
| // At first, we need to build empty map. | |
| // Empty map is just a function, it will return undefined when invoked. | |
| // When you set new key-value into map, it will wrap a new function around previous map, | |
| // and when you get something from map with key, it will pass key to every nested function until it match or hit empty map. | |
| const map = () => undefined; | |
| const set = map => (key, value) => q => q === key ? value: map; | |
| const get = map => key => typeof map === 'function' ? get(map(key))(key) : map; | |
| // Demo time! |
This file contains hidden or 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
| // basic idea | |
| (f => f(f)(5))(f => n => n == 0 ? 1 : (n * f(f)(n-1))); | |
| // This version doesn't work, because js is not lazy. | |
| // const Y = f => (x => f(x(x)))(x => f(x(x))); | |
| // const Y = f => (x => x(x))(x => f(a => x(x)(a))); | |
| const Y = f => (x => f(y => x(x)(y)))(x => f(y => x(x)(y))); |
This file contains hidden or 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
| // Stream | |
| const stream = f => (x => x(x))(y => init => [init, m => y(y)(f(m))]); | |
| const add3Stream = stream(n => n + 3); | |
| const mult2Stream = stream(n => n * 2); | |
| const inspect = stream(n => { | |
| console.log('inspect:' + n); | |
| return 0; | |
| }); | |
| const pipe = s1 => s2 => x => { |
This file contains hidden or 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
| javascript:function minutesSeconds(s){return(s-(s%=60))/60+(9<s?':':':0')+s}function start(){var currentURL=window.location.href;var bar=document.getElementsByClassName("ytp-progress-bar")[0];var seconds=bar.getAttribute("aria-valuenow");var secondsInMS=minutesSeconds(seconds);var URL=currentURL+"?t="+seconds;var obsidianFormat="["+secondsInMS+"]("+URL+")";navigator.clipboard.writeText(obsidianFormat);null;var elemDiv=document.createElement('div');elemDiv.innerHTML="<h1 style='font-size:100px; color:white; text-align:center; margin-top:2em;'>"+secondsInMS+"</h1>";elemDiv.style.cssText='position:absolute;width:100%;height:100%;opacity:0.8;z-index:1000;background:#000;';document.body.appendChild(elemDiv);setTimeout(function(){elemDiv.style.display="none"},600)}start(); |
OlderNewer