Skip to content

Commit

Permalink
Merge pull request #13 from flojoy-ai/jeff/iteration-and-functions
Browse files Browse the repository at this point in the history
feat: functions, sequences, conditionals, editable constant
  • Loading branch information
jackparmer authored Jun 7, 2024
2 parents 3af7ed9 + 6431f3e commit bee015f
Show file tree
Hide file tree
Showing 51 changed files with 2,205 additions and 707 deletions.
2 changes: 1 addition & 1 deletion blocks/flojoy/control/slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


@ui_input
def slider(x):
def slider(x: int) -> int:
return x
6 changes: 6 additions & 0 deletions blocks/flojoy/control/toggle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from captain.decorators import ui_input


@ui_input
def toggle(x: bool):
return x
5 changes: 5 additions & 0 deletions blocks/flojoy/logic/clock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import reactivex as rx


def clock():
return rx.interval(1 / 60)
14 changes: 14 additions & 0 deletions blocks/flojoy/logic/conditional.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from typing import TypedDict
from captain.types.builtins import Ignore


class Output(TypedDict):
true: Ignore | None
false: Ignore | None


def conditional(b: bool) -> Output:
return Output(
true=None if b else Ignore(),
false=Ignore() if b else None,
)
2 changes: 2 additions & 0 deletions blocks/flojoy/logic/false.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def false() -> bool:
return False
5 changes: 5 additions & 0 deletions blocks/flojoy/logic/sequence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import reactivex as rx


def sequence(start: int = 0, stop: int | None = None, step: int | None = None):
return rx.range(start=start, stop=stop, step=step)
2 changes: 2 additions & 0 deletions blocks/flojoy/logic/true.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def true() -> bool:
return True
2 changes: 1 addition & 1 deletion blocks/flojoy/math/arithmetic/add.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def add(x, y):
def add(x: int, y: int) -> int:
return x + y
2 changes: 1 addition & 1 deletion blocks/flojoy/math/arithmetic/subtract.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def subtract(x, y):
def subtract(x: int, y: int) -> int:
return x - y
4 changes: 2 additions & 2 deletions blocks/flojoy/math/constant.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def constant():
return 2
def constant(val: int) -> int:
return val
6 changes: 6 additions & 0 deletions blocks/flojoy/math/rand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import random
from typing import Any


def rand(x: Any = None) -> int:
return random.randint(0, 100)
Loading

0 comments on commit bee015f

Please sign in to comment.