ToCode
Open in Telegram
××פ×× ×§×¦×Ø×× ×××Ŗ×× ×Ŗ×× ×××Ŗ ×× ×× ×¤×Ø×§
Show more1 420
Subscribers
+124 hours
+17 days
-430 days
Posts Archive
1 420
××ר×× Next.JS - פרק 1 ××Ŗ×§× × ×פר×××§× ×Ø×ש××
×ש×××¢ ××××× ××¦× ×פ××Ø× ××× ××× ×× ××ש××ר ××Ŗ ×Ŗ×××Ŗ ××××× ×©××× ×Ø××§× ××× ×ש×× ××××× ××Ŗ×§××¤× ××ר×× next.js ש××Ŗ××Ŗ× ×ר×ש. ××§××× ×©×Ŗ×צ×× ×××Ŗ× ×××¢×× ×× ×××ר ×××Ø× ×× ××× ××××××Ŗ ××××ש××.
××× Next.JS
× ×§×”× ×'×× ××” ××× ×”×××× ×פ××Ŗ×× ××ש××× Full Stack ××××”×”×Ŗ ר×××§×, ×××פשרת ×× × ×פר×××§× ××× ×××Ŗ×× ×× ××Ŗ ×§×× ×¦× ×שרת ××× ××Ŗ ×§×× ×¦× ×××§××. ×××ש ×©× ×פר×××××רק ××× ×¢× ×§×××Ŗ ×× ×××Ŗ פר×××§× ×××× ××רצ×× ×××§× ××× ×§×× ×¦× ×©×Ø×Ŗ ××§×× ×¦× ××§××, ×× ×©×××¤× ×××Ŗ× ×××××Ø× ×××× ×§×× ×פר×××§×× ×Ø×××§× ××ש××. ××תר ×××, next.js × ×צר ×¢× ××× ××רת vercel ××ש ×× ××× ××××××× × deployment ×¢× ××¢× × ×©×××, ×× ×©×פשר ××××× ××Ŗ ×פר×××§× ××××× ×Ŗ ×פ××Ŗ×× ×××× ××Ø× × ×××× ××§××Ŗ.
פר×××§× ×Ø×ש××
×ש××× ××צ×ר פר×××§× next.js ר×ש×× ×× × ×¦×Ø×× ×Ø×§ ×××Ŗ×§×× ××Ŗ node.js ××× ××פע×× ××Ŗ ×פק×××:
npx create-next-app@latest 01-intro
×××¢× ××Ŗ ×¢× ×הפר ש××××Ŗ (×× × ×××Ø×Ŗ× ××××× ××Ŗ ×ר×ר××Ŗ ×××××). ×× ×ש××¢××Ŗ××Ŗ ××תר ×××ר ××§× ××××§×× ×§×× ×¤×××רצ×××Ŗ ×××פ××§ ×עצ×× × ××× ×פ××× ××תר ×§× ××צ×רת פר×××§× ×¢× vite. ×××Ø× ×צ×רת ×פר×××§× ×פשר ×פת×× ×©×Ø×Ŗ ×פ××Ŗ×× ××§××× ×¢× ×××:
cd 01-intro
npm run dev
פת×××Ŗ ×פר×××§× ×©× ×צר ××”××××Ŗ פ××Ŗ×× ×Ŗ×Ø×× ×× × ×©×ש ××”× ××× ×©× × ×§×צ×× ××¢× ××× ×× ××× ×Ŗ××× ××Ŗ××§×××Ŗ app, ×ר×ש×× × ×§×Ø× layout.tsx ×××©× × × ×§×Ø× page.tsx. × layout ×× × ×××¦× ××Ŗ ××§×× ×××:
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
import './globals.css'
const inter = Inter({ subsets: ['latin'] })
export const metadata: Metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
</html>
)
}
×× page.tsx ××Ŗ ××§×× ×××:
import Image from 'next/image'
export default function Home() {
return (
<main className="flex min-h-screen flex-col items-center justify-between p-24">
<div className="z-10 max-w-5xl w-full items-center justify-between font-mono text-sm lg:flex">
<p className="fixed left-0 top-0 flex w-full justify-center border-b border-gray-300 bg-gradient-to-b from-zinc-200 pb-6 pt-8 backdrop-blur-2xl dark:border-neutral-800 dark:bg-zinc-800/30 dark:from-inherit lg:static lg:w-auto lg:rounded-xl lg:border lg:bg-gray-200 lg:p-4 lg:dark:bg-zinc-800/30">
Get started by editing
<code className="font-mono font-bold">src/app/page.tsx</code>
</p>
<div className="fixed bottom-0 left-0 flex h-48 w-full items-end justify-center bg-gradient-to-t from-white via-white dark:from-black dark:via-black lg:static lg:h-auto lg:w-auto lg:bg-none">
<a
className="pointer-events-none flex place-items-center gap-2 p-8 lg:pointer-events-auto lg:p-0"
href="https://vercel.com?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
By{' '}
<Image
src="/vercel.svg"
alt="Vercel Logo"
className="dark:invert"
width={100}
height={24}
priority
/>
</a>
</div>
</div>
<div className="relative flex place-items-center before:absolute before:h-[300px] before:w-[480px] before:-translate-x-1/2 before:rounded-full before:bg-gradient-radial before:from-white before:to-transparent before:blur-2xl before:content-[''] after:absolute after:-z-20 after:h-[180px] after:w-[240px] after:translate-x-1/3 after:bg-gradient-conic after:from-sky-200 after:via-blue-200 after:blur-2xl after:content-[''] before:dark:bg-gradient-to-br before:dark:from-transparent before:dark:to-blue-700 before:dark:opacity-10 after:dark:from-sky-900 after:dark:via-[#0141ff] after:dark:opacity-40 before:lg:h-[360px] z-[-1]">
<Image
className="relative dark:drop-shadow-[0_0_0.3rem_#ffffff70] dark:invert"1 420
××××Ŗ ×ר×××× - Coalesce
××§×× ××× ××× ×××ר ×××××§ ×× ×§××× ×רק××§×” ×¢× ××¢×Ø× bob ×××פ××× name, ××× ×× ×§××× ××צ×ר ××ש, ××× ××× ×× ×¢××©× ×××××§ ××Ŗ ×× ×©×Ø×¦×× ×. ×× ×¢××©× ××§××, ×× ×××¢×× ×××× × ×Ŗ×§× ×××Ŗ×?
g
.V()
.coalesce(
__.has('person', 'name', 'bob'),
__.addV('person').property('name', 'bob')
)
.iterate()
×××¢×× ××§××
×פק××× coalesce ×©× ×ר×××× ××§×××Ŗ ×הפר ×פשר××××Ŗ ×××Ŗ×§××××Ŗ ××רף ×××צעת ×××Ŗ× ××¤× ××”×ר ×¢× ×©××××¢× ××פשר××Ŗ ש×××××Ø× ×¦×××Ŗ ×Ŗ×§××. ××× ×××××Ø× ××§×× ××× ×××ר ×××Ŗ××× ××× ×צ××Ŗ×× ××רף, ××צ×× ×¦×××Ŗ ש×ש ×× ××Ŗ ×××פ××× name ×¢× ××¢×Ø× bob, ×× ×§××× ×××××ר ×××Ŗ× ××× ×× ×§××× ×××××¢ × addV. ××× ×× ××× ×× ×¢×××.
×××¢×× ××§×× ××× ×© coalesce ××פ××¢ ×××Ø× V() ×××× ××× ×××¤×¢× ×¢× ×× ×צ××Ŗ×× ××רף, ××××ר ××× ×¦×××Ŗ × ××××§ ×× ×¤×Ø× ×× ××× ××Ŗ××× × has ××× ×× × × ×”× ××××”××£ צ×××Ŗ ××× ×¢× addV, ×× ×©××ר×× ××××”×¤× ×©× ×××× ×¦××Ŗ××. ×××××Ŗ ××Ø×¦× ××”×§××× ×¢× ××§×× ×××:
@main def main() =
val graph = TinkerGraph.open
val g = traversal.withEmbedded(graph)
println(g.addV("person").property("name", "a").next())
println(g.addV("person").property("name", "b").next())
println("--- 1")
println(g.V().elementMap().toList)
g.V()
.coalesce(
has("person", "name", "bob"),
addV("person").property("name", "bob"))
.iterate()
println("--- 2")
println(g.V().elementMap().toList)
××פ××”× ××Ŗ ×פ××:
--- 1
[{id=0, label=person, name=a}, {id=2, label=person, name=b}]
--- 2
[{id=0, label=person, name=a}, {id=2, label=person, name=b}, {id=4, label=person, name=bob}, {id=6, label=person, name=bob}]
××××ר × ××¦×Ø× ×©× × ×¦××Ŗ×× ××ש×× ×¢× ××©× bob.
פ×תר×× ××¢×רת fold
××× ××Ŗ×§× ××? ××× ×¤×©×× ×× ×§××× ××פש ××Ŗ ×צ×××Ŗ ××× ×¢××× ××פע×× ××Ŗ coalesce. ×××¢×× ××× ×©× ××”××× ××× ×¢××× ×××××©× ×× ×צ×××Ŗ ×× ×§××× ××עצ×ר ××Ŗ ×× ×ש××××Ŗ×. ××× ×ש ××××”××£ ×¦×¢× fold ש×××”×£ ××Ŗ ×× ×צ××Ŗ×× ×××Ŗ××××× ×רש××× ××פת×× ××Ŗ ×××Ŗ× ×Ø×©××× ××Ŗ×× × coalesce. ×× ××§×צ×ר ××§××:
@main def main() =
val graph = TinkerGraph.open
val g = traversal.withEmbedded(graph)
println(g.addV("person").property("name", "a").next())
println(g.addV("person").property("name", "b").next())
println("--- 1")
println(g.V().elementMap().toList)
g.V()
.has("person", "name", "bob")
.fold()
.coalesce(
unfold(),
addV("person").property("name", "bob"))
.iterate()
println("--- 2")
println(g.V().elementMap().toList)
×× ×©××צר רק צ×××Ŗ ××× ×¢× ××©× bob.
פ×תר×× ××¢×רת merge
×××רה×××Ŗ ×הפ××§ ××ש××Ŗ ×©× ××× ×§×Ø×¤×פ ×פשר ××שת×ש × merge ××× ×××”×× ××Ŗ ×× ×××××× ××× ×ש×× ×× × ×× ×”×× ×××× ×¦×××Ŗ ××¤× ××פ××× ××× name. ××§×× × ×Ø×× ×××:
g.mergeV(Map[Object, Object](
T.label -> "person",
"name" -> "bob"
).asJava)
.iterate()
×× ×¢×× ×××××× ××× ××¤× ××פ××× ×× ×©×× ×× × ×××ר×× ×× ×××× ×פ×תר×× ××× ×××. ×שצר×× ×××× ××¤× ×××”×× ×צ××Ŗ×× ××ר×× (×××××× ×× ×§××× ×¦×××Ŗ person ש××× friend ×©× bob) ×× × ×¦××Ø× ××××ר ××ר××§ ×©× × coalesce ×× fold.1 420
×Ŗ××§×× ×× ×§×××, ×Ŗ××§×× ×× ×§×©×× ×××××§××Ŗ
×פר×××§× Node.JS שע×××Ŗ× ×¢××× ×צ××Ŗ× ××Ŗ ×ש××Ø× ××××Ŗ:
const [host, port] = address.split(':');
×××ש××× ×××Ŗ× ××××”××£ פ××Ø× ×ר×רת ××××, ×× ×©×× ×××Ŗ×××Ŗ ×× ××”×Ŗ××××Ŗ ×× ×§××××Ŗ××× ××הפר × ×©×Ŗ×ש ××ר×רת ××××× 8080.
××Ŗ××§×× ××§× ××× ××”× ×××:
const [host, port = '8080'] = address.split(':');
××Ŗ××§×× ××§×©× ××× ×××Ŗ×××× ×¢× ×× ×©×ר ×××ר×× ×©×שת×ש×× ×××× ×××× ××” ××Ŗ×× address, ×××©× ××××× ×©×שת×ש×× ×××××× ×××Ŗ×× http ×××Ŗ×××, ××××”××£ × ×Ŗ××, ×××¢××Ŗ ××©× ×©× × host, ×××Ŗ×× ××Ŗ×××Ŗ IP ×× ×Ŗ×§×× × ×× ×××××× ××¢××××Ŗ ××ר××Ŗ ××”×× ××. ×§×× ××× ×¦×Ø×× ××פר×× ××× ××× ×× ×× ×©××¤×¢× × ××Ŗ ××§×× ××× ×× ×× ×©×¢××©× ×ש×× ×¢× ××§×× ××פ××¢× ×, ×××פשר ××× ××× ××©× × ××× ×× ×× ×× ××××× ×©×××××Ŗ ×צ××Ø× ×©×Ŗ×Ŗ××× ××× ××× ××שת×ש. ש×× ×× ××× ××× ×§×©× ×× ×ש××Ø× ×××Ŗ× ×§×××Ø× ×פ×× ×§×¦×× ×©× ×¢×©×Ø××Ŗ ש×ר××Ŗ ×××× ×× ×× ×× ××× ××¢×ר×××× ×××.
×ש×ש ×”× ××××§××Ŗ ××× ×× ×× × ×ר××ש×× ×× ×× ××צע ×× ×Ŗ××§×× ×× ×§×©××, ×פ××× ×××× ×©××רש×× ×Ø×פק××ר×× × ×ש××¢××Ŗ×.
××¦×¢×Ø× × ×ר×× ××ער×××Ŗ ×ש××× ×× ×× ×× ×ש×× ×× ××§×× ××¢×ר×××× ×××, ×× ×× ××× ×¢× ×× ×©××ער××Ŗ ××× ××××§××Ŗ ××ש ×××× ××§×Ø× ×§×¦× ×× ××Ŗ××¢×××, ×× ×©××Ŗ××§×× ××§×©× × ×Ø×× ×××¢× ×××Ŗ× ×פשר×.
×× ×©××× ××××ר ש××Ŗ××§×× ××§×©× ×× ×××× ××Ŗ××§×× ××§×©× ×××ר×× ××§××. ×× ××× ×××Ŗ ×× ×× × ××§×××× ××××× ××Ŗ ××צע ×××Ŗ×, ×××× ×× ×¦× ×××Ŗ× ××× ×××Ŗ×× ×”× ××××§××Ŗ ×¢××ר ××Ŗ××§×× ××§×©× ×××.1 420
××פ ×”×§×××: ×××רת ×Ŗ×צ×× ×¢×Ŗ××××Ŗ
××× ×× ×× ××××× × ×©× Future ××”×§××× ××× ×××× × ×¤×××Ŗ ××Ŗ×××× ×הפר×××Ŗ ××× cats effect ××× ××××× ×××× ×××××Ŗ ש××××©× ×××¢×××Ŗ פש××××Ŗ, ××× ××רש ×ר××× ×××ש ×©× ×§×× ××Ŗ××× ××Ŗ. × ×Ø×× ××× ×× ×¢××× ××Ø× ××××× ×¤×©×××.
×פ×× ×§×¦×× ×××× ×××צרת ××××××Ø× ×Ø×©××× ×©× ×הפר××:
def createNumbers(): List[Int] =
(1 to 10).map(_ =>
Thread.sleep(Random.nextInt(500))
Random.nextInt(100)).toList
×××××× ×ש ×××××”× - ×ש××× ×××צר ×הפר ×× ×× × ××××× ×¢× ××¦× ×©× ×× ×¢× Thread.sleep. ×× × ××§× ××Ŗ ×רש××× ××××ׄ ×× × ×”× ×××פ××” ×××Ŗ× ×¢× ×§×× ×××:
createNumbers().foreach(println(_))
××§×× ×××× ×¢× ×©×רש××× ×××× ×××× × ×רק ×× ××פ××” ×××× ×××Ŗ ××Ŗ ×× ×-10 ×הפר××. ×× ×¢××× ×××××Ŗ ××¢×××Ŗ× ×× ×× ×××××ש×× ×”××× ××Ŗ××× ××Ŗ ×Ŗ×”×Ŗ××× ×¢× ×©×××× ××¤× × ×©×צ×××× ×××צר ××Ŗ ×× ×רש××× ××£ ×הפר ×× ×××פה. ××¢×רת ×× ×× ×× Future ×× × ×××× ×××צר רש××× ×©×Ŗ××× ×××× × ××§×× ×××צ×× × ×× ××¤× × ×©×× ×פר×××× ××ש×× ××××××.
×רע××× ××××× ××× ×©×××§×× ×××××ר רש××× ×©× ×הפר×× ×× × ××××ר רש××× ×©× ×Ŗ×צ×××Ŗ ×¢×Ŗ×××××Ŗ (×× Future ××××¦× ×Ŗ×צ×× ×¢×Ŗ××××Ŗ ×©× ××ש××). ×× ××§××:
def createFutureNumbers(): List[Future[Int]] =
(1 to 10).map(_ => Future[Int] {
Thread.sleep(Random.nextInt(500))
Random.nextInt(100)
}).toList
××§×× ×××צ×× × ×× × ×××§× ×× Future ×"×××××§" ×× ×§×× ×©×××צע ×××Ø× ×©×××Ŗ× ××ש×× ×¢×Ŗ××× ×××× ××××. ××××××Ŗ ××××¤×”× ×× ××××:
val futures = createFutureNumbers()
futures.foreach(f => f.onComplete(i => println(i.get)))
×××ר ××× ×× × ×Ø××¦× ×××××Ŗ ×¢× ×©×× ×××ש×××× ××¢×Ŗ××××× ××”×Ŗ××××, ××× ×× × ×××¤× ××Ŗ רש×××Ŗ ×××ש×××× ××¢×Ŗ××××× × Future ××× ×©×××× ×××× ×ש×× ×פר×××× ×רש××× ××ש×× ××¢×רת ×פ×× ×§×¦×× sequence. פ×× ×§×¦×× × ×הפת ××©× Await.ready ×Ŗ××× ×¢× ×© Future ××”×Ŗ××× ××× ×Ŗ×פשר ××Ŗ××× ××Ŗ ×ר×ׄ ×¢× ××”××× ×× ×××פה××Ŗ. ×”× ××× ××§×× ×××צ×× × ××××:
@main
def f(): Unit =
val futures = createFutureNumbers()
futures.foreach(f => f.onComplete(i => println(i.get)))
Await.ready(Future.sequence(futures), Duration.Inf)
××תר ×××, × Future ××”×§××× ×××× ×¤×× ×§×¦×× ××©× flatMap ש××פשרת ××××”××£ ×× ×××©× ××ש××. ××××Ø× ×××××× × × ×× ×©×××Ø× ×©××הפר ×××× ××Ŗ××× ××Ŗ ×Ŗ××× ×¢×× ×הפר ×××× ×©× ×××Ŗ ××¤× ××הפר ש×××©× ××× ×Ŗ×¢×× ×××Ŗ× ×ר××××¢, ×××”××£ ×Ŗ×פ××” ××Ŗ ר××××¢× ×× ××הפר××. ××§×× ×××¢×××× ××× ×××× ××”× ×××:
def f(): Unit =
val futures = createFutureNumbers().map {f =>
f.flatMap(i => Future({
Thread.sleep(i)
i * i
}))
}
futures.foreach(f => f.onComplete(i => println(i.get)))
Await.ready(Future.sequence(futures), Duration.Inf)1 420
×× ×××× ×××× ××Ŗ ××
×©× × ×××××ש×× ××××× ×פ×××Ŗ×× ×××××× ××× ×הפר ××× ×Ø×ש×× × ×©×§×××× ×××ר×:
* v1 - *
def is_prime_v1(n):
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
* v2 - *
from math import sqrt
def is_prime_v2(n):
return not any(n % i == 0 for i in range(2, int(sqrt(n)) + 1))
××××× ××××× ××× ××× ××ש××× ×¦×Ø×× ××××ר ××× ××××× ××Ŗ ××§××. ×××××ש ×ר×ש×× ×הפ××§ ××××× ×× ×× ×¤×× ×§×¦×× ××××Ŗ×××× ×¢× ××××××Ŗ for × range. ×××××ש ××©× × ××ר ××רש ×××ר××Ŗ ×¢× Generator Comprehension, ×¢× ×פ×× ×§×¦×× any ××¢× ×¤×§×××Ŗ import.
×× ×××©× ××× ×§×Ø×× ××תר? ×§×©× ×××××. ×× ×©×××× ××× ×©×ש×× ×××Ŗ××× ××Ŗ ×ר×× ×××ש×××Ŗ ×©× ××§×× ××ער××Ŗ ×××”×××× ×× ××× × ××Ŗ×. × Code Review ×ער××Ŗ ××× "××§×× ××”×ר×× ×××" ×× "××§×× ×× ×§×Ø××" ×××ר××Ŗ ×ר×× ×¤×¢××× "××§×× ×שת×ש ×פ×××Ŗ ××× ××ש×××", ×××¦× ××©× ×, ×ער××Ŗ ××× "××§×× ××Ŗ×××× ×××" ×× "××§×× ×§×©× ××Ŗ××××§×" ××”× ××× ×××ר××Ŗ "××§×× ×שת×ש ×××תר ××× ××ש××× ××שפ×". ×ש××§×× ×¢× ×××× ××§×× ×©×× ×× × ×××Ŗ××× ×××××× ×××× ×××Ŗ× × ×ר×× ×¢× ××©×¤× ×××§×× ×¢×¦××.1 420
×× ×××× ×××× ××Ŗ ××
×©× × ×××××ש×× ××××× ×פ×××Ŗ×× ×××××× ××× ×הפר ××× ×Ø×ש×× × ×©×§×××× ×××ר×:
* v1 - *
def is_prime_v1(n):
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True
* v2 - *
from math import sqrt
def is_prime_v2(n):
return not any(n % i == 0 for i in range(2, int(sqrt(n)) + 1))
××××× ××××× ××× ××× ××ש××× ×¦×Ø×× ××××ר ××× ××××× ××Ŗ ××§××. ×××××ש ×ר×ש×× ×הפ××§ ××××× ×× ×× ×¤×× ×§×¦×× ××××Ŗ×××× ×¢× ××××××Ŗ for × range. ×××××ש ××©× × ××ר ××רש ×××ר××Ŗ ×¢× Generator Comprehension, ×¢× ×פ×× ×§×¦×× any ××¢× ×¤×§×××Ŗ import.
×× ×××©× ××× ×§×Ø×× ××תר? ×§×©× ×××××. ×× ×©×××× ××× ×©×ש×× ×××Ŗ××× ××Ŗ ×ר×× ×××ש×××Ŗ ×©× ××§×× ××ער××Ŗ ×××”×××× ×× ××× × ××Ŗ×. × Code Review ×ער××Ŗ ××× "××§×× ××”×ר×× ×××" ×× "××§×× ×× ×§×Ø××" ×××ר××Ŗ ×ר×× ×¤×¢××× "××§×× ×שת×ש ×פ×××Ŗ ××× ××ש×××", ×××¦× ××©× ×, ×ער××Ŗ ××× "××§×× ××Ŗ×××× ×××" ×× "××§×× ×§×©× ××Ŗ××××§×" ××”× ××× ×××ר××Ŗ "××§×× ×שת×ש ×××תר ××× ××ש××× ××שפ×". ×ש××§×× ×¢× ×××× ××§×× ×©×× ×× × ×××Ŗ××× ×××××× ×××× ×××Ŗ× × ×ר×× ×¢× ××©×¤× ×××§×× ×¢×¦××.1 420
×××Ŗ× ×¤×Ŗ×× ××Ŗ×××× ×©× ×Ø×× (××: ××× ×× × ×¦×Ø×× ×¢×× ×××)
×ש ×©× × ×”×××× ×©× ×©××¢×ר×× ×שע×××× - ×פע××× ×× ×שע×× ×× ×× ×× × ×××ר×× ××Ŗ ×× ××××ר, ××פע××× ×× ××§×¦× ×× ××Ŗ××× ××× ×× × ×¤×©×× ×× ×××× ×× ××××.
×ש××¢××× ×××”×× ×ר×ש×× ××תר ×§×. ×ש×× × ××××¢ ×× ×§××Ø× ×× × ×××× ×× ××× ×ש×××× ×××ש××Ŗ, ×פ×××”×××§, ××××××ר ×× ××× ×× × ××× ××ר. ×¤×¢× ×××× ××§××Ŗ ×פשר ×××צ×× ××Ŗ ××©× ××Ø×§× ××× ×ר×××Ŗ ש××××ר ×¢×××× ×××ר.
×ש××¢××× ×××תר ×§×©× ××× ×× ×××”×× ××©× ×. ש××¢××× ×©× ××הר ××× × ××× ××Ŗ×ש, ×× ×× ×× × ×שק××¢×× ×××× ×× ×Ø××× ××× ×”××Ŗ ×××××, ××× ×”××Ŗ ××××××§ ××Ŗ ×קצ×. ×××× × ×©× ×רצ×× ×× ×××× ×§×©× ×ר×××Ŗ ××Ŗ ×פער. ×× ×ש××¢××× ××ר×××.
××©× ×Ŗ×§××× ×ש××¢××× ××× ×××× ×”××× ×§× ×©×× × ×××¢×. ××××Ŗ× ×Ø××¢ ×× ×× × ×Ø×§ ××פש×× "××”××ר ××Ŗ ×פער", ×× ×”××Ŗ "××××× ××× ×©×פשר", ×××ש×× ××קש×× ×פ××× ×©×× ×שע×× ×× ×××× × ××××Ŗ הפר ש×ש ×¤× ×ש×× ×ש×× ×ש×××××× ××Ŗ ××××Ŗ ×× ×Ŗ×××ר. ×¢×ש×× ×קש××××, ×××Ø× ×× ×××× ××. ××ר×× ×Ø×¦×× ××××× ××¢×× ××× × ×¢×¦×××Ŗ ×××¤× ×פ××§, ×× ××××£ ××ר ××××¢ ×× ×©×××× ×× ×Ø××¦× ×ש×××¢.
×××××Ŗ ××××××Ŗ ××× ×©×פער ××תר ×××× ××× ×©×××× ××× ×Ø××¦× ××××××. ×× ×× ×××× "רע×××" ×§×× ×©×¦×Ø×× ×ש×××¢ ×××× ××”×Ŗ×ר, ××× ×¢××××Ŗ ×ש××× ×ש××¢××Ŗ××Ŗ ××× ××”××ר ××Ŗ ×××Ŗ× ×¤×¢×Ø. ×× ×× ××§×רה × ×Ŗ× × ×× ××©× ××¦× ×©×¢×, ×××× ×× × ×¦×Ø×× ×ר××¢ שע××Ŗ ××× ××××× ××Ŗ ×× ××©× ×××. ××§×¦× ×©×× ×××× ×××××Ŗ ש×× × ×××§×¦× ×©× ××ר×× ××× ××”××× ××××× ××§×¦× ×©×× ××Ŗ××× ×× ××× ×¤×©×× ××Ŗ×ש.
×××¦× ××× ×פ×תר×× ××× ××× ×××××× ×©×¢××× ××× ×××צ×× ××§×¦× ×©××, ×× ×× ×× ×× ××§×¦× ×©× ××××Ŗ× ×× ××××××. ×× ××”×ר ×ר×××Ŗ ××Ŗ ×××Ŗ× ×©××¢×ר ××× ×¤×¢×××. ×× ××”×ר ××שק××¢ ש×××¢××× ×××£ תר×××××, ×× ×× ××ש×× ××ר פתר ×××Ŗ× ××××. ××××× ×× ×× ×Ŗ×ר××Ŗ ×××§×××¦× ×× ×××× ××תר ××× ××× ×××× ×©×× ××.
××§×¦× ××××× ×©×¢××× ××× ××§×¦× ×©×¢××× ×¢××ר×.
1 420
××פ ×”×§×××: ××פהת ×××× ×××צע Pipeline
×שפ××Ŗ פ×× ×§×¦××× ×××××Ŗ ××× ××××Ŗ ××× ×§×××'ר ×× ××××§×”×ר, ×ש ××פר××ר Pipeline שש××× ××Ŗ ××Ŗ×צ×× ×©× ×¤×× ×§×¦×× ×××Ŗ ××Ŗ×ר ×§×× ×פ×× ×§×¦×× ×××× ××Ŗ×ר. ×××××× ××§×× ××× ××§×××'ר:
(->> 10
(range)
(map #(* %1 %1))
(reduce +)
(println))
×××§× ××Ŗ ××הפר 10, ש××× ×××Ŗ× ××Ŗ×ר ×פר××ר ×פ×× ×§×¦×× range, ×××Ø× ×× ×××§× ××Ŗ ××Ŗ×צ×× ×©× range ××Ŗ×ר ×§×× ×פ×× ×§×¦×××Ŗ × map, ××Ŗ ××Ŗ×צ×× ×©× map ××× ×©××× × reduce ×××Ŗ ×× ×ש×× × println ××× ×××פ××”. ×”× ××× × ×§×× ×¢× ×××”× ××Ŗ ×”××× ×Ø××××¢× ××הפר×× ××פה ×¢× ×Ŗ×©×¢.
×× ×ש ××¢×× ×××ש×× ×פשר ×××××ר ××§×××Ŗ פ×× ×§×¦×× ×©××פ××”× ××Ŗ ×פר××ר×× ×©×§×××× ××××××Ø× ×××Ŗ×, ××× ××××”××£ ×××Ŗ× ×××צע × Pipeline ××× ×ר×××Ŗ ×”××××” ××× ×××:
(defn debug [n]
(println n)
n)
(->> 10
(debug)
(range)
(debug)
(map #(* %1 %1))
(debug)
(reduce +)
(println))
××פה××Ŗ ×××× ××× ×¢××ר××Ŗ ××××× ×× ×§××Ø× ×©× ×××Ŗ×§× ××¢×××Ŗ ×שצר××.
×××¢×ר ××”×§××× ×××× ××Ŗ××¢××¢×Ŗ× ××× ×× ×× ×××, ××××× ×©××”×§××× ×§×Ø××× ×שרשרת ×פ×× ×§×¦×××Ŗ ×שת×שת ××Ŗ×××ר ×××Ŗ××××Ŗ ×©× ×Ŗ×× ××Ŗ ××× ×× ×¢×¦×××. ××× × ×Ø×× ×§×× ×”×§××× ××§××× ××§×××'ר ××Ŗ××××Ŗ ×פ××”×:
println(
(0 to 9)
.map(_.pow(2))
.sum
)
×× ×× ××× ×¤×©×× ××”×§××× ×× × ×× ×××× ××שת×ש פע×××× ×פר××ר ×©× ×¤×× ×§×¦×× ×× ×× ××××Ŗ ××× ×××§×× ×× ×ש ×× ×¤×× ×§×¦×× ×××¢×××Ŗ ×ר××××¢, ×××× ×××× ××Ŗ ××הפר ×××ר×× ××× ××”××××× ×תשע ××ש פ×× ×§×¦×××Ŗ sum ×× ×× ×¦×Ø×××× ××Ŗ reduce. ×××× ×××Ŗ ×©× × ××ר×× ×¤×××¢×× ×¤× ×××××× - ×ר×ש×× ××× ×© println צר×× ×××××Ŗ× ×××Ŗ××× ××Ŗ×ר פ×× ×§×¦××, ×××©× × ×©×× ×× ×××Ŗ×× ×¤×× ×§×¦×××Ŗ debug ××× ×©×××Ŗ× ×× ××§×××'ר ××× ×× ×××§ ××פ××פ××××.
×ש×××Ŗ× × ×× ×× ×× × Extensions ×©× ×”×§××× ××פשר ×פת×ר ××Ŗ ×©×Ŗ× ×××¢×××Ŗ ×××”××Ŗ ××§×××Ŗ. ×× × ××××ר Extension ×× ×Ø× ×©×××”××£ ××Ŗ ×פ×× ×§×¦×× debug ××× ×¢×Ø× ×שפ×. ×× × ×Ø×× ×××:
extension [A](value: A)
def debug(): A =
println(value)
value
}
@main
def main(): Unit =
println(
(0 to 9)
.debug()
.map(_.pow(2))
.debug()
.sum
)
××פ××:
NumericRange 0 to 9
Vector(0, 1, 4, 9, 16, 25, 36, 49, 64, 81)
285
××תר ×××, ×××× ×©×××§ ×××××××§××× ××©×¤× ×××ש××× ×צ××Ø× ×¢×¦×× (×××©× Range), ×פשר ××××”××£ ×¢×× ×¤×× ×§×¦×× ×©×Ŗ×פ×× ×××ר××ר×× ×רש××××Ŗ ××× ×Ŗ×פ××” ×××Ŗ×, רק ש××× ×× ×× ××פע×× ×××Ŗ× ×¢× ××ר×× ××× ×”×פ×××:
extension [A](value: A)
def debug(): A =
println(value)
value
def eagerDebug(): A = value match {
case it: Iterable[_] =>
println(it.toList)
value
case it: Iterator[_] =>
println(it.toList)
value
case _ =>
println(value.getClass)
value
}
@main
def main(): Unit =
println(
(0 to 9)
.eagerDebug()
.map(_.pow(2))
.debug()
.sum
)
××× ××ר ×××”×¤× × ××Ŗ debug × ××× ××שת×ש ×× ×× ××”××£ ×פ××פ×××× ××× ×××פ××” ××”×× ×× ×§×××'ר:
@main
def main(): Unit =
(0 to 9)
.eagerDebug()
.map(_.pow(2))
.debug()
.sum
.debug()1 420
הקר×פ××× × JavaScript? ×Ŗ× × ×¦'×× ×” ×××× ××××ר
×××Ŗ ×××¢×××Ŗ ×ש×××ש × node.js ×××Ŗ×××Ŗ הקר×פ××× ××× ××§××ׄ package.json, ×× ××תר × ××× ×צ××Ø× ×צרף ×××Ŗ× ×הקר××¤× ××× ×××Ŗ×§×× ××Ŗ ××Ŗ×××××Ŗ. ××Ŗ××× ××Ŗ ×××× × node.js ××Ŗ×× ×§×× ×××××× ×©× ×××××× wikipedia ×¢× npm ×× ××××× ×ר×ׄ ×××:
const wiki = require('wikipedia');
(async () => {
try {
const page = await wiki.page('Batman');
console.log(page);
//Response of type @Page object
const summary = await page.summary();
console.log(summary);
//Response of type @wikiSummary - contains the intro and the main image
} catch (error) {
console.log(error);
//=> Typeof wikiError
}
})();
×ש××× ×©××× ×Ŗ×¢××× ×× × ×¦×Ø×× ××צ×ר ×××Ŗ× ××Ŗ××§×× ×§××ׄ package.json ×××פע×× npm install ×× ××פע××
npm install wikipedia
×ש×רת ×פק××× ××¤× × ×רצ×.
×¢×ש×× ×××× × ×Ø×× ××× ×××Ŗ× ×ר××§ ××¢××× ×¢× ××× ×. ××ר ר×ש×× ×¦×Ø×× ××©× ××Ŗ ××Ŗ ש×רת × require × import, ××צ××× ×©×× × ×××¢× ××Ŗ ×××××× × npm ×× ×©×§×× ××Ŗ××× ××Ŗ ××××:
import wiki from 'npm:wikipedia';
(async () => {
try {
const page = await wiki.page('Batman');
console.log(page);
//Response of type @Page object
const summary = await page.summary();
console.log(summary);
//Response of type @wikiSummary - contains the intro and the main image
} catch (error) {
console.log(error);
//=> Typeof wikiError
}
})();
××××× ×× ×Ø×§ ×שתפר. ×× × ×ר×ׄ ××Ŗ ××§×× ×××× × ××Ŗ××× ×××××ר ×××Ŗ×:
$ deno run demo.js
ā ļø ā Deno requests env access to "npm_config_no_proxy".
ā Run again with --allow-env to bypass this prompt.
ā Allow? [y/n] (y = yes, allow; n = no, deny) >
ש×× ××, ××× ×××ר, ×הקר××¤× ××¢×× ××× ×קר×× ××××¢ ×××©×Ŗ× × ×”×××× ××פ××× ×××Ŗ× ××Ŗ ××©× ×©× ××©×Ŗ× × ××”××××. ×× × ×××× ××שר ×¢× y ×× ××ר×ׄ ×××ש ×¢× --allow-end ××× ×©×× ×ש×× ××תר ×¢× ×××©× ×××©×Ŗ× × ×”××××. ×× × ××שר ×××ש×××× ×ש××××Ŗ ×××××Ŗ. ×× ×× × ×Ø×× ××”××£:
$ deno run demo.js
ā
Granted env access to "npm_config_no_proxy".
ā
Granted env access to "NPM_CONFIG_NO_PROXY".
ā
Granted env access to "no_proxy".
ā
Granted env access to "NO_PROXY".
ā
Granted env access to "npm_config_https_proxy".
ā
Granted env access to "NPM_CONFIG_HTTPS_PROXY".
ā
Granted env access to "https_proxy".
ā
Granted env access to "HTTPS_PROXY".
ā
Granted env access to "npm_config_proxy".
ā
Granted env access to "NPM_CONFIG_PROXY".
ā
Granted env access to "all_proxy".
ā
Granted env access to "ALL_PROXY".
ā
Granted read access to "/Users/ynonp/Library/Caches/deno/npm/node_modules".
ā
Granted read access to "/Users/ynonp/Library/Caches/deno/node_modules".
ā
Granted read access to "/Users/ynonp/Library/Caches/node_modules".
ā
Granted read access to "/Users/ynonp/Library/node_modules".
ā
Granted read access to "/Users/ynonp/node_modules".
ā
Granted read access to "/Users/node_modules".
ā
Granted read access to "/node_modules".
ā
Granted net access to "en.wikipedia.org".
××××Ø× ×× ××××¢ ×פ×× ×ר××× ×©× ×הקר×פ×. ×× ×× × ×”××× ×¢× ×הקר××¤× ×× × ×××× ×¤×¢× ×××× ××ר×ׄ ×××Ŗ× ×¢× ×××Ŗ×××:
$ deno run --allow-net --allow-read --allow-env demo.js
××× ×××× ×¢× ×ש××××Ŗ.
×”× ××× ××Ŗ××× ××רצת הקר××¤× ×¢× ××× × × ×Ŗ× × ×× ×©× × ×תר×× ××Ŗ ×ש××¢××Ŗ××× ×¢× ×¤× × node:
1. ××× ×¦××Ø× ××§××ׄ package.json, ×× ××Ŗ×××××Ŗ רש××××Ŗ ××Ŗ×× ×§××ׄ ×הקר××¤× ××××Ŗ×§× × ×§×ר××Ŗ ××××××××Ŗ ×××Ø×¦× ×ר×ש×× ×.
2. ×× × ××שש ×ר×× ×¤×××Ŗ ××§×× ×××× ×, ×× ××ר×רת ××××× ×הקר××¤× ×Ø×„ ×¢× ××¢× ×××× ×רש×××Ŗ.1 420
×××× ××××Ŗ× - ×× ××× ×¤×©×× ××פש ×××”××£ ×××××× ×Ø××××ר×
××Ŗ××× ×××× Advent Of Code ××××× × ×× × ×× ×Ø×× ×× ×צ××× ×פת×ר ××Ŗ ×× ××××××Ŗ ש×× ××©× × ×¢× ×××× ×ר×ש×× ×× ×פשר ×××תר. ××××× ××××××Ŗ ××× ×¦×Ø×× ××צ×× ××ר×× ××Ŗ×× ××§×”×××. ×× ××× ××”××× ×¢× ×©× ×Ŗ×§××× ××ר××§ ××§×× ×©××§××§× ×××.
×תר××× ×××ר××§
××”×פ×ר ××××× ××× ××צ×× ×”×¤×Ø××Ŗ ××Ŗ×× ×©×רת ××§×”×, ×ש×הפר××Ŗ ××××××Ŗ ×××פ××¢ ××Ŗ×ר הפר××Ŗ ××ש ××× 4, 9 ×× 2 ×× ××Ŗ×ר ×©× ××”×¤×Ø× ××× four, nine ×× two. ×× ×× × ×¦×Ø×××× ××צ×× ×××× ×Ŗ× ×©×רת ××§×”× ××Ŗ ××”××¤×Ø× ×ר×ש×× × ×××”××¤×Ø× ×××ר×× × ××. ×××©× ×ש×ר×:
24
××”××¤×Ø× ×ר×ש×× × ××× 2 ××××ר×× × ××× 4.
×ש×ר×:
abc7d
××”××¤×Ø× 7 ××× ×× ××”××¤×Ø× ×ר×ש×× × ××× ×××ר×× ×.
××ש×ר×:
eightwo
××”××¤×Ø× 8 ××× ×ר×ש×× × × 2 ××× ×××ר×× ×.
× ××”×× 1 - ××פ×ש ×× ×××פע××
רע××× ×Ø×ש×× ×©×פשר ×× ×”××Ŗ ××× ××צ×× ××Ŗ ××”××¤×Ø× ×ר×ש×× × ××××ר×× × ××× ××פ×ש ×××××××, ×פ×××Ŗ×× ×× ××××:
>>> digits = [str(i) for i in range(10)] + ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
>>> digits_r = '|'.join(digits)
>>> re.findall(digits_r, "1abc3")
['1', '3']
××× ×¢××× ×¢× ×©×× ×פה××§ ××¢×××:
>>> re.findall(digitsr, "eightwo")
['eight']
×× ×××¢×× ×©× t ×ש××Ŗ×£ ×× × eight ××× × two ××× ××¢ ×××××××× ×ר××××ר××× ××ר ×××× ××Ŗ × t ×ש××× ××¦× ××Ŗ eight.
פ×תר×× - ××פ×ש ×פ××
××××¢×ר ××Ø× ×××× ××פש ×××”××£ ×××××× ×Ø×××××Ø× × ×רשת ×צ×רת×××Ŗ - ×××©× ××פ×× ××Ŗ ×× ×××§×”××× ××¤× × ×××פ×ש ××× ××פ×× ×××Ø× ×××Ø× ×©××צ××× ××× ×××¢×Ŗ ×××× ×”××¤×Ø× ×צ×× ×. ×פ×××Ŗ×× ×× ×§×:
>>> digits_re = '|'.join([d[::-1] for d in digits])
>>> [r[::-1] for r in re.findall(digits_re, "eightwo"[::-1])]
['two']
Available now! Telegram Research 2025 ā the year's key insights 
