►
From YouTube: Functional JS - Understanding ADTs - Tom Wilson
Description
ADTs are powerful functional patterns that enable us to control how pure functions or calculations can be applied to values in a container. This video shows the concept of ADTs without functional jargon.
For more information on ADTs checkout the blog post: https://blog.hyper.io/understanding-adts/
A
A
So
what
I
would
like
to
do
is
kind
of
show
you
guys
what
an
8080t
is
and
how
you
can
use
it
in
a
very
simple
approach
and
then
later
I'll
do
another
screencast
on
async
adts,
which
will
allow
you
to
essentially
compose
side
effects
and
operate
on
side
effects
without
actually
calling
the
side
effects
and
then
once
you've
done.
All
of
your
logic
then
call
the
side
effects
and
you
are
essentially
pushing
your
side
effects
or
actions
to
the
edges
of
your
app
and
not
kind
of
embedding
it
in
your
business
logic.
A
But
first,
let's
talk
about
why
adt,
so
adts
really
gives
you
all
of
the
ilities
in
your
code
right.
It
creates
maintainability,
testability,
reliability
and
extensibility,
but
learning
them
can
be
a
challenge
because
you
have
to
kind
of
change.
Your
mindset
from
maybe
the
imperative
kind
of
style
of
programming
that
we
we've
grown
accustomed
to
and
really
think
more
in
terms
of
data
flow
right
data
flowing
through
a
pipeline.
A
So
what
we're
going
to
do
and
we're
going
to
use
dino
for
this,
so
I'm
running
dino
and
I've
got
a
little.
You
know
kind
of
console
set
up
and
every
time
I
type,
let's
see.
A
B
A
We
should
see
it
kind
of
pop
over
on
the
right.
Maybe
let's
see
I
think
I
have
to
save
it.
That
will
help
right.
There
we
go
so
we've
got
this
little.
You
know
demo
console
setup,
so
we
can
go
through
some
exercises
because
it
makes
a
lot
of
sense
when
you
see
it
in
action.
You
know
an
adt
is
basically
a
container
and
that
container
allows
you
to
put
values
in
and
then
it
gives
you
a
set
of
rules
on
how
you
can
manage
mutate
or
change
those
values
by
calling
methods.
A
Pop
and
that's
going
to
actually
pop
the
value
out,
so
if
we
we
run
this,
we
should
get
an
error.
Let's
see,
we
cannot
read
one
of
undefined,
so
maybe
it
doesn't
like
me
not
having
a
colon
up
here.
Let's
see
okay,
so
we
did
that
now,
let's,
let's
assign
it
to
a
variable.
That
would
be
helpful
right.
B
A
A
It
will
provide
the
value
that's
in
the
container
and
then
it
will
replace
that
value
with
another
container
it'll
replace
the
whole
container,
with
whatever
container
you
return.
So
if
we
return,
you
know
42
and
we
have
to
wrap
it
in
that
container,
so
we're
returning
a
whole
container.
Then
it's
going
to
replace
this
container
that
we've
mapped
and
have
done
all
these
functions
on
with
this
new
container
42..
A
A
A
So
let's
do
that
and
let's
go
ahead
and
just
call
it
id.
So
this
will
be
id
and
it's
going
to
take
a
value
and
then
it's
going
to
put
it
in
an
object
and
that
object
is
going
to
you
know
kind
of,
contain
the
value
and
it's
going
to
have
a
map
function
and
it's
going
to
have
a
chain
function.
A
A
Now,
if
you
don't
like
this
syntax,
you
can
use
compose
or
something
like
that,
but
we'll
just
leave
that
that's
pretty
simple
and
then
our
chain.
A
Basically
a
chain
needs
to
return
a
adt
of
the
same
type,
so
in
this
case
id,
but
our
function
that
that
we
pass
into
the
chain
function
will
actually
be
responsible
for
returning
that.
So
all
we
have
to
do
is
kind
of
call
that
function
and
pass
the
value.
So
that's
super
easy,
and
that
is
our
new
fancy.
Adt.
A
B
A
And
we
can
do
you
know
any
function
we
pass
in
and
whatever
value
it
returns
is
going
to
replace
the
value
in
the
box
or
in
the
adt
right,
and
we
can
also
do
our
chain
as
well
so
chain
instead
of
flat
map,
we
grab
the
value
and
then
we
simply
call
id
and
then
whatever
we
want
and
return
that.
So
then
that's
going
to
return
id
42
and
ignore
all
the
computations
prior
to
that.
A
But
but
that's
basically,
an
adt
is
you're,
taking
a
value
you're,
putting
it
in
a
container
and
then
you're
running
these
functions
on
that
and
then
once
you're
done,
you
call
extract
and
they
can
get.
You
know
kind
of
very
interesting
because
you
have
this
chainable
interface.
You
can
do
nested
adts
and
you
can
kind
of
really
add
some
complex
logic
to
that.
A
Now,
where
it
gets
interesting,
is
in
the
next
demo,
I'm
going
to
show
async
adts
and
the
sync
adts
allow
you
to
use
the
same
kind
of
patterns
to
essentially
wrap
side
effects
in
pure
functions
and
run
them
through
a
pipeline
and
then,
when
you're
done
actually
execute
the
side
effect
functions.