When the button is clicked or the Enter key is pressed while typing in the input, the text below is updated. The text below shows the text from the input as well as if the information is updated by pressing Enter or clicking on the button.
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
import {run} from '@cycle/run'; | |
import {makeDOMDriver, div, button, br, input} from '@cycle/dom'; | |
import xs from 'xstream'; | |
import sampleCombine from 'xstream/extra/sampleCombine'; | |
function main (sources) { | |
const click$ = sources.DOM.select('.button').events('click').startWith(false); | |
const input$ = sources.DOM.select('.input').events('input'); | |
const text$ = input$.map(ev => ev.target.value).startWith(''); | |
const combined$ = click$.compose(sampleCombine(text$)); |
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
-- original JS code | |
-- var list = [ 3, 42, 73, 2 ]; | |
-- var min = list[0], max = list[0]; | |
-- for (var i = 0; i < list.length; i++) { | |
-- min = Math.min(min, list[i]); | |
-- max = Math.max(max, list[i]); | |
--} | |
-- we will use Html.text to show the result | |
import Html exposing (text) |
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
-- original JS code | |
--var result = 0; | |
--for ( var i = 0; i <= 10; i++) { | |
-- result += i; | |
--} | |
-- we will use Html.text to show the result | |
import Html exposing (text) | |
-- let's call the function `sumMe` |
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
-- we will show the result with a single html text node | |
import Html exposing (text) | |
-- let's call the function euler1 and say it receives a single Int param and returns a single Int param | |
euler1 : Int -> Int | |
euler1 num = | |
-- no recursion this time, only lists | |
let | |
-- create a list with numbers from 1 to num - 1 | |
list = [1..num-1] |
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
-- we will show the result with a single html text node | |
import Html exposing (text) | |
-- let's call the function euler1 and say it receives two Int params and returns a single Int param | |
euler1 : Int -> Int -> Int | |
euler1 num numMax = | |
-- break point of the recursion is when num increased to numMax | |
if num == numMax then | |
0 | |
else |
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
-- we will show the result with a single html text node | |
import Html exposing (text) | |
-- let's call the function euler1 and say it receives a single Int param and returns a single Int param | |
euler1 : Int -> Int | |
euler1 num = | |
-- break point of the recursion is when num is 0 | |
if num == 0 then | |
0 | |
else |
I hereby claim:
- I am iliyan-trifonov on github.
- I am iliyan (https://keybase.io/iliyan) on keybase.
- I have a public key whose fingerprint is E823 F836 CB93 1FC8 76C5 6792 C71F 8218 E912 BE87
To claim this, I am signing this object: