4. 4
DO I REALLY NEED TO LEARN
A NEW LANGUAGE?
LET’S JUST USE JAVASCRIPT!
5. 5
Elm
JS ES6 + Babel + Webpack + React + Redux + Immutable
or
Typescript
or
Brunch
or
Gulp
or
Grunt
or
Cycle.js + RxJS
or
seamless-
immutableNot even close
12. 12
A LITTLE MORE OBVIOUS SYNTAX
-- isNotEven = not . isEven
isNotEven = not << isEven
isNotEven' = isEven >> not
-- let lastChar = head $ toList $ reverse "foobar"
let lastChar = head <| toList <| reverse "foobar"
dot =
scale 2 (move (20,20) (filled blue (circle 10)))
dot' =
circle 10
|> filled blue
|> move (20,20)
|> scale 2
13. 13
RECORDS
carolina =
{ name = "Carolina de Jesus"
, age = 62
}
abdias =
{ name = "Abdias Nascimento"
, age = 97
}
people =
[ carolina
, abdias
]
carolina.name
.name carolina
List.map .name people
-- ["Carolina de Jesus", "Abdias Nascimento"]
39. 39
ELM TEST
module Example where
import ElmTest exposing (..)
tests : Test
tests =
suite "A Test Suite"
[ test "Addition" <|
assertEqual (3 + 7) 10
, test "This test should fail" <|
assert False
]
40. 40
ELM TEST BDD STYLE
module Example where
import ElmTestBDDStyle exposing (..)
tests : Test
tests =
describe "A Test Suite"
[ it "adds two numbers" <|
expect (3 + 7) toBe 10
, it "fails for non-sense stuff" <|
expect True toBe False
]
41. 41
PROPERTY-BASED TESTING
module Example where
import ElmTestBDDStyle exposing (..)
import Check.Investigator exposing (..)
tests : Test
tests =
describe "A Test Suite"
[ it "adds two numbers" <|
expect (3 + 7) toBe 10
, it "fails for non-sense stuff" <|
expect True toBe False
, itAlways "ends up with the same list when reversing twice" <|
expectThat
(list -> List.reverse (List.reverse list))
isTheSameAs
(identity)
forEvery
(list int)
]
43. 43
FROM JS TO ELM
port addUser : Signal (String, UserRecord)
myapp.ports.addUser.send([
"Tom",
{ age: 32, job: "lumberjack" }
]);
myapp.ports.addUser.send([
"Sue",
{ age: 37, job: "accountant" }
]);
JS
44. 44
FROM ELM TO JS
port requestUser : Signal String
port requestUser =
signalOfUsersWeWantMoreInfoOn
myapp.ports.requestUser.subscribe(databaseLookup);
function databaseLookup(user) {
var userInfo = database.lookup(user);
myapp.ports.addUser.send(user, userInfo);
}
JS