Platform
Resources
Pricing
Sign in
Get started
Joshua Horowitz
Workspace
Fork
Public
By
Joshua Horowitz
Edited
Oct 5, 2023
Insert cell
Insert cell
refunc
=
import
(
"https://cdn.skypack.dev/@engraft/refunc@0.0.1"
)
Insert cell
refunc2
=
import
(
"https://esm.sh/@engraft/refunc@0.0.1"
)
Insert cell
square
=
refunc
.
hooks
(
(
x
)
=>
{
const
squared
=
refunc
.
hookMemo
(
(
)
=>
{
console
.
log
(
'squaring'
,
x
)
return
x
*
x
;
}
,
[
x
]
)
;
return
squared
;
}
)
;
Insert cell
{
var
mem
=
new
refunc
.
RefuncMemory
(
)
;
console
.
log
(
square
(
mem
,
3
)
)
;
// → squaring 3
// → 9
console
.
log
(
square
(
mem
,
3
)
)
;
// → 9
console
.
log
(
square
(
mem
,
4
)
)
;
// → squaring 4
// → 16
console
.
log
(
square
(
mem
,
4
)
)
;
// → 16
// But note that we only remember the very
// latest input:
console
.
log
(
square
(
mem
,
3
)
)
;
// → squaring 3
// → 9
}
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
refunc
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
refunc2
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
square
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML