►
From YouTube: Either-This-or-That
Description
This screencast is about the Either data type. https://blog.hyper63.com/either-this-or-that/
A
Hello
in
this
screencast
we're
going
to
talk
about
either
either
this
or
either
that
either
is
a
data
type
that
basically
allows
you
to
make
safe
functions.
So
you
can,
you
know,
run
some
function
and
if
it
returns
an
error,
you
can
use
an
either
function
to
return
either
a
left
or
a
right
and
through
your
pipeline
right
will
continue
down.
The
pipeline
left
will
exit
out
of
the
pipeline.
A
So
I'm
going
to
show
a
few
examples
of
that:
we're
going
to
use
deno
or
dino
and
an
either
library
and
some
ramda.
A
So
the
first
thing
we'll
do
is
just
kind
of
fold
that
out
and
it's
either
going
to
return
a
left
which
this
function
handles
the
left
side
and
we'll
just
do
console
log
left
and
then
the
value
and
the
second
function
is
the
right.
So
we
will
console
log
that
with
the
right
and
return
the
value
and
if
we
run
that
we
should
get
one,
because
the
default
of
the
of
is
a
right
instance.
So
it'll
always
return
the
right.
Now.
A
If
we
want
to,
let's
say,
add,
add
to
this
value,
you
know
we
can
map
over
it.
So,
let's
pull
in,
add
and
and
go
ahead
and
pull
in
multiply
from
ramba
and
then
we'll
just
map,
and
what
map
does
is
allows
you
to
run
a
function
inside
the
container.
A
A
A
That's
it
so
if
we
run
that,
then
we
get
two
right
and
if
we
map
over
another
function,
let's
say
multiply
by
two
and
we
run
that
we
get
a
right
of
four.
So
so
that's
basically
how
either
works
a
lot.
You
know
as
any
kind
of
functional
type.
You
can
create
a
pipeline,
we
call
map
or
chain,
and
then
you
can
fold
at
the
end
and
it's
gonna
return
the
value
that's
inside
that
container.
A
So
what
if
this
value
is
null
right
so
or
if
it's
not
a
number,
so
the
add
and
the
multiply
functions
is
kind
of
expecting
it
to
be
a
number.
So
if
it's
not
a
number,
that's
not
good.
So
we
need
to
do
a
check
to
make
it
safe
right.
So
we
can
create
a
function
down
here
called
is
number
it
takes
a
value
and
then
basically
it's
just
gonna
say:
if
is
number,
then
we
want
to
return
the
value,
the
right
of
the
the
value
right.
A
So
we
want
to
return
a
new
either
with
the
value
and
then,
if
it
is
not
a
number,
then
we
want
to
return
left
and
we'll
just
say
not
a
number.
But
we
could
kind
of
put
any
kind
of
value
in
here
and
what's
going
to
happen
is
when
this
runs
we're
going
to
chain
and
the
reason
we're
going
to
use
chain
is
this
function
is
going
to
return
another
either
and
that
either
can
be
either
a
right
or
a
left.
So
it's
kind
of
like
a
flat
map.
A
A
Let's
see
right's
not
defined
cool,
so
let's
bring
in
right
and
left
from
either
okay
and
we
get
four.
So
what
happened?
Is
we
checked
if
the
value
in
the
container
is
a
number?
And
if
so,
then
we'll
run
the
maps
and
let's
make
it
not
so
so,
let's
make
it
a
null
right
and
when
we
run
that
we
get
left
is
not
a
number.
So
what
happens?
Is
this
chain
returns
a
left
and
the
either
says?
A
Okay,
I'm
not
doing
a
map
not
doing
a
map,
and
then,
when
we
come
to
fold,
I'm
going
to
run
the
left
function
in
the
fold
and
that's
basically
how
it
either
works
now
with
either
you
can
get
a
couple
of
common
methods
to
make
things
just
a
little
bit
easier.
A
A
If
we
run
that
we
get
is
null,
but
if
I
put
a
value
in
here,
we
get
is
not
null.
If
I
put
undefined,
we
get
is
null
so
from
noble
can
basically
allow
you
to
check
you
know
a
value
coming
from
somewhere.
Maybe
you
can't
control
and
make
sure
that
it's
not
null
before
you
get
into
your
your
business
logic.
A
Let's
look
at
try
catch,
try
catch
takes
a
function
and
then
it's
going
to
run
that
function
and
if
that
function
throws
an
error,
then
it's
going
to
run
a
return,
a
lift.
If
the
function
doesn't
throw
an
error,
it
will
return
the
result
of
that
function
as
a
write.
So
we
can
test
that
out
by
just
doing
try
catch
and
just
putting
a
function
in
here
and
we'll
just
go
ahead
and
throw
a
new
error.
A
A
He
got
me
so
the
left
means
that
it
found
an
error
and
and
it
caught
it
and
it
returned
it
as
a
left
and
then
the
right.
A
Let's
just
do
no
error
right,
so
if
we
run
that
we
should
get
you
got
me,
we
we
had
an
error
and
we
can
get
access
to
that
error
right.
So
when
it
does
throw
the
air
we
can
get
access
to
it
and
write
it
out.