SlideShare a Scribd company logo
1 of 37
Download to read offline
Functional Programming with
     Streams in node.js
Who Am I?

  HP webOS Framework Team

  @CrabDude (Twitter, Github, etc…)

  Organizer BayNode & Dallas.node

  Author:

    trycatch – async try/catch in node.js

    stepup – step node.js control flow + trycatch

    tiki – in-browser package manager
The Problem
     VFS         VFS           VFS

hermesClient hermesClient hermesClient

              hermesBuild        3rd Party API


    hermes      hermesDeploy



   Ares
  (browser)
The Goal

  Don’t buffer any data

  Don’t write to disk

  Minimize latency

  Allow reuse of functionality (e.g., readdir)

  Functionality may be local or remote (e.g., getFolder)
Why node.js?

“Node's goal is to provide an easy way to build
  scalable network programs.”
                                    – nodejs.org
node.js === JavaScript

JavaScript is the future of the web,
  and code reuse is its unfair advantage.
Basics

  EventEmitter

  Stream

  Traditional streams (aka non-node.js lazy streams)
EventEmitter: Example
EventEmitter: Extend
Streams

“Streams are to time as arrays are to space.”
              – Jed Schmidt @ JSConf.eu/2010
Readable Streams

  Events: data, end, error, close

  Methods: pause, resume, end, destroy
Writable Streams

  Events: drain, error, close, pause, resume

  Methods: write, end, destroy
readable.pipe(writeable)

Readable streams can be piped to writable streams
  (and vice-versa!)

  on(‘data’) => write()

  on(‘end’) => end()

  on(‘drain’) => resume()

  on(‘close’) => destroy()

  on(‘error’) => on(‘error’)

  on(‘pause’) => pause()
readable.pipe(writeable): Example
Lazy Streams

Streams in functional programming…
Lazy Streams: Higher Order Functions

A higher-order function is a function that does at least
  one of the following:

  Take one or more functions as input
  output a function
Lazy Streams: Lists
Got All That?
Hermes: Revisited
     FTP        Dropbox        Box.net   Filesystem

hermesFtp hermesDropbox hermesBox hermesFilesystem

               hermesBuild                 3rd Party API

                          hermesDeploy

     Ares
   (browser)
Still Got All That?
We need…

We need to recursively zip a directory…

  Let’s start with abstract implementation non-specific
   functional versions of…

    Filter paths from readdir

    Filter directories from paths

    Filter files from paths

    Recursively return all file paths in a directory
We need…

  More “abstract implementation non-specific functional
   versions” (errr…) of…

    ls (aka readdir)

    getFile (aka readFile)

    getFolder (stream of gets)
We need…

  Yet More AINSFV of...

    Zip a stream of files

    Allow node.js streams to be piped to lazy streams

       pipe(): lazy stream => node.js stream

       pump(): node.js stream => lazy stream
Almost there!
Now we can…

Zip a folder up using an arbitrary…

  getFile / readFile

  ls / readdir



… And stream the response! Yeeeeehaw!
Sweeeeeet.
Now What?

Since all the implementation specific functions
  are passed in, we can…
Port this to the browser!
Say whaaat?

node-browserify by @Substack does a lot of this already

    Stream, Buffer, Path, etc…

We need…

    Complete buffer implementation (browser has
     TypedArrays & ArrayBuffer)

    fs (browser has FileSystem API)

    zlib…

       inflate(), deflate(), gzip(), gunzip(), unzip()
Stay Tuned.

I’m currently porting the fs and buffer modules to
  the browser, and eventually zlib.

http://github.com/crabdude/fs-browserify
http://github.com/crabdude/buffer-browserify
http://github.com/crabdude/zlib-browserify
We’re HIRING!
            webOS Framework Team
If you think this is pretty cool…
   Or you think I’M pretty cool…

Stop by the Enyo booth or talk to me afterwards.
Thank you.

        adam.crabtree@palm.com
https://github.com/Gozala/streamer/blob/master/readme.js
http://en.wikipedia.org/wiki/Higher-order_function
https://github.com/mikeal/request
http://felixge.s3.amazonaws.com/11/nodejs-streams.pdf
https://github.com/substack/node-browserify

Functional Programming in JavaScript:
http://igstan.ro/posts/2011-05-02-understanding-monads-with-
  javascript.html
http://ndc2011.macsimum.no/mp4/Day2%20Thursday/
  Track6%201500-1600.mp4
http://drboolean.tumblr.com/
http://osteele.com/sources/javascript/functional/

More Related Content

What's hot

Node.js for Rubists
Node.js for RubistsNode.js for Rubists
Node.js for RubistsSagiv Ofek
 
Applied Shell Scripting - stills to time-lapse
Applied Shell Scripting - stills to time-lapseApplied Shell Scripting - stills to time-lapse
Applied Shell Scripting - stills to time-lapseShoaib Sufi
 
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"Fwdays
 
Александр Махомет "Beyond the code или как мониторить ваш PHP сайт"
Александр Махомет "Beyond the code или как мониторить ваш PHP сайт"Александр Махомет "Beyond the code или как мониторить ваш PHP сайт"
Александр Махомет "Beyond the code или как мониторить ваш PHP сайт"Fwdays
 
Server side scripting smack down - Node.js vs PHP
Server side scripting smack down - Node.js vs PHPServer side scripting smack down - Node.js vs PHP
Server side scripting smack down - Node.js vs PHPMarc Gear
 
Webdevcon Keynote hh-2012-09-18
Webdevcon Keynote hh-2012-09-18Webdevcon Keynote hh-2012-09-18
Webdevcon Keynote hh-2012-09-18Pierre Joye
 
Basic testing with selenium
Basic testing with seleniumBasic testing with selenium
Basic testing with seleniumSøren Lund
 
HTTP::Parser::XS - writing a fast & secure XS module
HTTP::Parser::XS - writing a fast & secure XS moduleHTTP::Parser::XS - writing a fast & secure XS module
HTTP::Parser::XS - writing a fast & secure XS moduleKazuho Oku
 
Chenli linux-kerne-community
Chenli linux-kerne-communityChenli linux-kerne-community
Chenli linux-kerne-community力 陈
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...Tom Croucher
 
Searching CPAN Offline
Searching CPAN OfflineSearching CPAN Offline
Searching CPAN Offlineacme
 
Nginx وب سروری برای تمام فصول
Nginx وب سروری برای تمام فصولNginx وب سروری برای تمام فصول
Nginx وب سروری برای تمام فصولefazati
 
A slightly advanced introduction to node.js
A slightly advanced introduction to node.jsA slightly advanced introduction to node.js
A slightly advanced introduction to node.jsSudar Muthu
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and DjangoMichael Pirnat
 
Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Junichi Ishida
 
Developer-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneDeveloper-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneSylvain Zimmer
 
Jruby a Pi and a database
Jruby a Pi and a databaseJruby a Pi and a database
Jruby a Pi and a databasePhilipp Fehre
 
A rough guide to JavaScript Performance
A rough guide to JavaScript PerformanceA rough guide to JavaScript Performance
A rough guide to JavaScript Performanceallmarkedup
 
OSDC 2016 - DNS for Developers by Jan-Piet Mens
OSDC 2016 - DNS for Developers by Jan-Piet MensOSDC 2016 - DNS for Developers by Jan-Piet Mens
OSDC 2016 - DNS for Developers by Jan-Piet MensNETWAYS
 

What's hot (20)

Node.js for Rubists
Node.js for RubistsNode.js for Rubists
Node.js for Rubists
 
Applied Shell Scripting - stills to time-lapse
Applied Shell Scripting - stills to time-lapseApplied Shell Scripting - stills to time-lapse
Applied Shell Scripting - stills to time-lapse
 
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
Алексей Петров "PHP at Scale: Knowing enough to be dangerous!"
 
Александр Махомет "Beyond the code или как мониторить ваш PHP сайт"
Александр Махомет "Beyond the code или как мониторить ваш PHP сайт"Александр Махомет "Beyond the code или как мониторить ваш PHP сайт"
Александр Махомет "Beyond the code или как мониторить ваш PHP сайт"
 
Server side scripting smack down - Node.js vs PHP
Server side scripting smack down - Node.js vs PHPServer side scripting smack down - Node.js vs PHP
Server side scripting smack down - Node.js vs PHP
 
Webdevcon Keynote hh-2012-09-18
Webdevcon Keynote hh-2012-09-18Webdevcon Keynote hh-2012-09-18
Webdevcon Keynote hh-2012-09-18
 
Basic testing with selenium
Basic testing with seleniumBasic testing with selenium
Basic testing with selenium
 
HTTP::Parser::XS - writing a fast & secure XS module
HTTP::Parser::XS - writing a fast & secure XS moduleHTTP::Parser::XS - writing a fast & secure XS module
HTTP::Parser::XS - writing a fast & secure XS module
 
Chenli linux-kerne-community
Chenli linux-kerne-communityChenli linux-kerne-community
Chenli linux-kerne-community
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...
 
Searching CPAN Offline
Searching CPAN OfflineSearching CPAN Offline
Searching CPAN Offline
 
Nginx وب سروری برای تمام فصول
Nginx وب سروری برای تمام فصولNginx وب سروری برای تمام فصول
Nginx وب سروری برای تمام فصول
 
A slightly advanced introduction to node.js
A slightly advanced introduction to node.jsA slightly advanced introduction to node.js
A slightly advanced introduction to node.js
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
 
Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.Great Tools Heavily Used In Japan, You Don't Know.
Great Tools Heavily Used In Japan, You Don't Know.
 
Developer-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing oneDeveloper-friendly taskqueues: What you should ask yourself before choosing one
Developer-friendly taskqueues: What you should ask yourself before choosing one
 
5 things MySql
5 things MySql5 things MySql
5 things MySql
 
Jruby a Pi and a database
Jruby a Pi and a databaseJruby a Pi and a database
Jruby a Pi and a database
 
A rough guide to JavaScript Performance
A rough guide to JavaScript PerformanceA rough guide to JavaScript Performance
A rough guide to JavaScript Performance
 
OSDC 2016 - DNS for Developers by Jan-Piet Mens
OSDC 2016 - DNS for Developers by Jan-Piet MensOSDC 2016 - DNS for Developers by Jan-Piet Mens
OSDC 2016 - DNS for Developers by Jan-Piet Mens
 

Viewers also liked

Writing native bindings to node.js in C++
Writing native bindings to node.js in C++Writing native bindings to node.js in C++
Writing native bindings to node.js in C++nsm.nikhil
 
Use of 3D Immersive Technology for the Support of Gifted Learners
Use of 3D Immersive Technology for the Support of Gifted LearnersUse of 3D Immersive Technology for the Support of Gifted Learners
Use of 3D Immersive Technology for the Support of Gifted LearnersGiftedkids.ie
 
优丽奇中国 公司手册
优丽奇中国 公司手册优丽奇中国 公司手册
优丽奇中国 公司手册Goodrich Global
 
Goodrich Global Corporate Brochure
Goodrich Global Corporate  BrochureGoodrich Global Corporate  Brochure
Goodrich Global Corporate BrochureGoodrich Global
 
Digiaika - Mikä Muuttuu Markkinoinnissa
Digiaika - Mikä Muuttuu MarkkinoinnissaDigiaika - Mikä Muuttuu Markkinoinnissa
Digiaika - Mikä Muuttuu MarkkinoinnissaDarwin Oy
 
Accelerating innovation and diffusion of renewable energy technologies: techn...
Accelerating innovation and diffusion of renewable energy technologies: techn...Accelerating innovation and diffusion of renewable energy technologies: techn...
Accelerating innovation and diffusion of renewable energy technologies: techn...CambridgeIP Ltd
 
Voita peli verkossa: Parempia asiakkaita verkkopalvelun optimoinnilla
Voita peli verkossa: Parempia asiakkaita verkkopalvelun optimoinnillaVoita peli verkossa: Parempia asiakkaita verkkopalvelun optimoinnilla
Voita peli verkossa: Parempia asiakkaita verkkopalvelun optimoinnillaDarwin Oy
 
CambridgeIP Webinar: Developing a fact Based IP Strategy
CambridgeIP Webinar: Developing a fact Based IP StrategyCambridgeIP Webinar: Developing a fact Based IP Strategy
CambridgeIP Webinar: Developing a fact Based IP StrategyCambridgeIP Ltd
 
CambridgeIP: Case Studies Of Recent Client Engagements
CambridgeIP: Case Studies Of Recent Client EngagementsCambridgeIP: Case Studies Of Recent Client Engagements
CambridgeIP: Case Studies Of Recent Client EngagementsCambridgeIP Ltd
 
Goodrich Global 产品常见问题 (地板)
Goodrich Global 产品常见问题 (地板)Goodrich Global 产品常见问题 (地板)
Goodrich Global 产品常见问题 (地板)Goodrich Global
 
Blowin In The Wind
Blowin In The  WindBlowin In The  Wind
Blowin In The Windgoznevi
 
Renewable energy and water treatment: emerging opportunities
Renewable energy and water treatment: emerging opportunitiesRenewable energy and water treatment: emerging opportunities
Renewable energy and water treatment: emerging opportunitiesCambridgeIP Ltd
 
Smart camera monitoring system
Smart camera monitoring systemSmart camera monitoring system
Smart camera monitoring systemArvind Krishnaa
 
E11 Physics Evaluation Sheet
E11 Physics Evaluation SheetE11 Physics Evaluation Sheet
E11 Physics Evaluation Sheetguest411ccf79
 
The HFA pMDI Patent Landscape: Minefield or Goldmine
The HFA pMDI Patent Landscape: Minefield or GoldmineThe HFA pMDI Patent Landscape: Minefield or Goldmine
The HFA pMDI Patent Landscape: Minefield or GoldmineCambridgeIP Ltd
 
Burns supper (3ºb 2012 13)
Burns supper (3ºb 2012 13)Burns supper (3ºb 2012 13)
Burns supper (3ºb 2012 13)Rocio Torres
 
TodiCastle: villa rentals & historic hotel in Umbria
TodiCastle: villa rentals & historic hotel in UmbriaTodiCastle: villa rentals & historic hotel in Umbria
TodiCastle: villa rentals & historic hotel in UmbriaMario Santoro
 
Ota sosiaalinen media tehokäyttöön
Ota sosiaalinen media tehokäyttöönOta sosiaalinen media tehokäyttöön
Ota sosiaalinen media tehokäyttöönDarwin Oy
 

Viewers also liked (20)

Writing native bindings to node.js in C++
Writing native bindings to node.js in C++Writing native bindings to node.js in C++
Writing native bindings to node.js in C++
 
Use of 3D Immersive Technology for the Support of Gifted Learners
Use of 3D Immersive Technology for the Support of Gifted LearnersUse of 3D Immersive Technology for the Support of Gifted Learners
Use of 3D Immersive Technology for the Support of Gifted Learners
 
♥♥♥
♥♥♥♥♥♥
♥♥♥
 
Vision2music
Vision2musicVision2music
Vision2music
 
优丽奇中国 公司手册
优丽奇中国 公司手册优丽奇中国 公司手册
优丽奇中国 公司手册
 
Goodrich Global Corporate Brochure
Goodrich Global Corporate  BrochureGoodrich Global Corporate  Brochure
Goodrich Global Corporate Brochure
 
Digiaika - Mikä Muuttuu Markkinoinnissa
Digiaika - Mikä Muuttuu MarkkinoinnissaDigiaika - Mikä Muuttuu Markkinoinnissa
Digiaika - Mikä Muuttuu Markkinoinnissa
 
Accelerating innovation and diffusion of renewable energy technologies: techn...
Accelerating innovation and diffusion of renewable energy technologies: techn...Accelerating innovation and diffusion of renewable energy technologies: techn...
Accelerating innovation and diffusion of renewable energy technologies: techn...
 
Voita peli verkossa: Parempia asiakkaita verkkopalvelun optimoinnilla
Voita peli verkossa: Parempia asiakkaita verkkopalvelun optimoinnillaVoita peli verkossa: Parempia asiakkaita verkkopalvelun optimoinnilla
Voita peli verkossa: Parempia asiakkaita verkkopalvelun optimoinnilla
 
CambridgeIP Webinar: Developing a fact Based IP Strategy
CambridgeIP Webinar: Developing a fact Based IP StrategyCambridgeIP Webinar: Developing a fact Based IP Strategy
CambridgeIP Webinar: Developing a fact Based IP Strategy
 
CambridgeIP: Case Studies Of Recent Client Engagements
CambridgeIP: Case Studies Of Recent Client EngagementsCambridgeIP: Case Studies Of Recent Client Engagements
CambridgeIP: Case Studies Of Recent Client Engagements
 
Goodrich Global 产品常见问题 (地板)
Goodrich Global 产品常见问题 (地板)Goodrich Global 产品常见问题 (地板)
Goodrich Global 产品常见问题 (地板)
 
Blowin In The Wind
Blowin In The  WindBlowin In The  Wind
Blowin In The Wind
 
Renewable energy and water treatment: emerging opportunities
Renewable energy and water treatment: emerging opportunitiesRenewable energy and water treatment: emerging opportunities
Renewable energy and water treatment: emerging opportunities
 
Smart camera monitoring system
Smart camera monitoring systemSmart camera monitoring system
Smart camera monitoring system
 
E11 Physics Evaluation Sheet
E11 Physics Evaluation SheetE11 Physics Evaluation Sheet
E11 Physics Evaluation Sheet
 
The HFA pMDI Patent Landscape: Minefield or Goldmine
The HFA pMDI Patent Landscape: Minefield or GoldmineThe HFA pMDI Patent Landscape: Minefield or Goldmine
The HFA pMDI Patent Landscape: Minefield or Goldmine
 
Burns supper (3ºb 2012 13)
Burns supper (3ºb 2012 13)Burns supper (3ºb 2012 13)
Burns supper (3ºb 2012 13)
 
TodiCastle: villa rentals & historic hotel in Umbria
TodiCastle: villa rentals & historic hotel in UmbriaTodiCastle: villa rentals & historic hotel in Umbria
TodiCastle: villa rentals & historic hotel in Umbria
 
Ota sosiaalinen media tehokäyttöön
Ota sosiaalinen media tehokäyttöönOta sosiaalinen media tehokäyttöön
Ota sosiaalinen media tehokäyttöön
 

Similar to Functional Programming with Streams in node.js

Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tourcacois
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backendDavid Padbury
 
Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?Dinh Pham
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...bobmcwhirter
 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersRutenis Turcinas
 
SD, a P2P bug tracking system
SD, a P2P bug tracking systemSD, a P2P bug tracking system
SD, a P2P bug tracking systemJesse Vincent
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDDSudar Muthu
 
Clustered PHP - DC PHP 2009
Clustered PHP - DC PHP 2009Clustered PHP - DC PHP 2009
Clustered PHP - DC PHP 2009marcelesser
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.Mike Brevoort
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevFelix Geisendörfer
 
PuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into OperationsPuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into Operationsgrim_radical
 
Docker Tips And Tricks at the Docker Beijing Meetup
Docker Tips And Tricks at the Docker Beijing MeetupDocker Tips And Tricks at the Docker Beijing Meetup
Docker Tips And Tricks at the Docker Beijing MeetupJérôme Petazzoni
 
Developing IT infrastructures with Puppet
Developing IT infrastructures with PuppetDeveloping IT infrastructures with Puppet
Developing IT infrastructures with PuppetAlessandro Franceschi
 
Node.js - A practical introduction (v2)
Node.js  - A practical introduction (v2)Node.js  - A practical introduction (v2)
Node.js - A practical introduction (v2)Felix Geisendörfer
 
Java Hates Linux. Deal With It.
Java Hates Linux.  Deal With It.Java Hates Linux.  Deal With It.
Java Hates Linux. Deal With It.Greg Banks
 
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016Zabbix
 
Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java Baruch Sadogursky
 

Similar to Functional Programming with Streams in node.js (20)

Node.js: A Guided Tour
Node.js: A Guided TourNode.js: A Guided Tour
Node.js: A Guided Tour
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?Asynchronous I/O in NodeJS - new standard or challenges?
Asynchronous I/O in NodeJS - new standard or challenges?
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack Developers
 
SD, a P2P bug tracking system
SD, a P2P bug tracking systemSD, a P2P bug tracking system
SD, a P2P bug tracking system
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
 
Clustered PHP - DC PHP 2009
Clustered PHP - DC PHP 2009Clustered PHP - DC PHP 2009
Clustered PHP - DC PHP 2009
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.
 
RuG Guest Lecture
RuG Guest LectureRuG Guest Lecture
RuG Guest Lecture
 
Nodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredevNodejs a-practical-introduction-oredev
Nodejs a-practical-introduction-oredev
 
PuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into OperationsPuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into Operations
 
Node js beginner
Node js beginnerNode js beginner
Node js beginner
 
Docker Tips And Tricks at the Docker Beijing Meetup
Docker Tips And Tricks at the Docker Beijing MeetupDocker Tips And Tricks at the Docker Beijing Meetup
Docker Tips And Tricks at the Docker Beijing Meetup
 
Developing IT infrastructures with Puppet
Developing IT infrastructures with PuppetDeveloping IT infrastructures with Puppet
Developing IT infrastructures with Puppet
 
Demo 0.9.4
Demo 0.9.4Demo 0.9.4
Demo 0.9.4
 
Node.js - A practical introduction (v2)
Node.js  - A practical introduction (v2)Node.js  - A practical introduction (v2)
Node.js - A practical introduction (v2)
 
Java Hates Linux. Deal With It.
Java Hates Linux.  Deal With It.Java Hates Linux.  Deal With It.
Java Hates Linux. Deal With It.
 
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
 
Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java Everything you wanted to know about writing async, concurrent http apps in java
Everything you wanted to know about writing async, concurrent http apps in java
 

Recently uploaded

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 

Recently uploaded (20)

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 

Functional Programming with Streams in node.js

  • 1. Functional Programming with Streams in node.js
  • 2. Who Am I?   HP webOS Framework Team   @CrabDude (Twitter, Github, etc…)   Organizer BayNode & Dallas.node   Author:   trycatch – async try/catch in node.js   stepup – step node.js control flow + trycatch   tiki – in-browser package manager
  • 3. The Problem VFS VFS VFS hermesClient hermesClient hermesClient hermesBuild 3rd Party API hermes hermesDeploy Ares (browser)
  • 4. The Goal   Don’t buffer any data   Don’t write to disk   Minimize latency   Allow reuse of functionality (e.g., readdir)   Functionality may be local or remote (e.g., getFolder)
  • 5. Why node.js? “Node's goal is to provide an easy way to build scalable network programs.” – nodejs.org
  • 6. node.js === JavaScript JavaScript is the future of the web, and code reuse is its unfair advantage.
  • 7.
  • 8. Basics   EventEmitter   Stream   Traditional streams (aka non-node.js lazy streams)
  • 11. Streams “Streams are to time as arrays are to space.” – Jed Schmidt @ JSConf.eu/2010
  • 12. Readable Streams   Events: data, end, error, close   Methods: pause, resume, end, destroy
  • 13. Writable Streams   Events: drain, error, close, pause, resume   Methods: write, end, destroy
  • 14. readable.pipe(writeable) Readable streams can be piped to writable streams (and vice-versa!)   on(‘data’) => write()   on(‘end’) => end()   on(‘drain’) => resume()   on(‘close’) => destroy()   on(‘error’) => on(‘error’)   on(‘pause’) => pause()
  • 16. Lazy Streams Streams in functional programming…
  • 17. Lazy Streams: Higher Order Functions A higher-order function is a function that does at least one of the following:   Take one or more functions as input   output a function
  • 20. Hermes: Revisited FTP Dropbox Box.net Filesystem hermesFtp hermesDropbox hermesBox hermesFilesystem hermesBuild 3rd Party API hermesDeploy Ares (browser)
  • 21. Still Got All That?
  • 22. We need… We need to recursively zip a directory…   Let’s start with abstract implementation non-specific functional versions of…   Filter paths from readdir   Filter directories from paths   Filter files from paths   Recursively return all file paths in a directory
  • 23.
  • 24. We need…   More “abstract implementation non-specific functional versions” (errr…) of…   ls (aka readdir)   getFile (aka readFile)   getFolder (stream of gets)
  • 25.
  • 26. We need…   Yet More AINSFV of...   Zip a stream of files   Allow node.js streams to be piped to lazy streams   pipe(): lazy stream => node.js stream   pump(): node.js stream => lazy stream
  • 27.
  • 29. Now we can… Zip a folder up using an arbitrary…   getFile / readFile   ls / readdir … And stream the response! Yeeeeehaw!
  • 30.
  • 32. Now What? Since all the implementation specific functions are passed in, we can…
  • 33. Port this to the browser!
  • 34. Say whaaat? node-browserify by @Substack does a lot of this already   Stream, Buffer, Path, etc… We need…   Complete buffer implementation (browser has TypedArrays & ArrayBuffer)   fs (browser has FileSystem API)   zlib…   inflate(), deflate(), gzip(), gunzip(), unzip()
  • 35. Stay Tuned. I’m currently porting the fs and buffer modules to the browser, and eventually zlib. http://github.com/crabdude/fs-browserify http://github.com/crabdude/buffer-browserify http://github.com/crabdude/zlib-browserify
  • 36. We’re HIRING! webOS Framework Team If you think this is pretty cool… Or you think I’M pretty cool… Stop by the Enyo booth or talk to me afterwards.
  • 37. Thank you. adam.crabtree@palm.com https://github.com/Gozala/streamer/blob/master/readme.js http://en.wikipedia.org/wiki/Higher-order_function https://github.com/mikeal/request http://felixge.s3.amazonaws.com/11/nodejs-streams.pdf https://github.com/substack/node-browserify Functional Programming in JavaScript: http://igstan.ro/posts/2011-05-02-understanding-monads-with- javascript.html http://ndc2011.macsimum.no/mp4/Day2%20Thursday/ Track6%201500-1600.mp4 http://drboolean.tumblr.com/ http://osteele.com/sources/javascript/functional/