From b8a86465bc2897195694b1aa03c49eecf61c9a64 Mon Sep 17 00:00:00 2001 From: Andrey Nikiforov Date: Thu, 10 Oct 2024 09:11:50 -0700 Subject: [PATCH] add fst & snd --- src/foundation/core/__init__.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/foundation/core/__init__.py b/src/foundation/core/__init__.py index 69cf03132..efc2f980d 100644 --- a/src/foundation/core/__init__.py +++ b/src/foundation/core/__init__.py @@ -1,4 +1,4 @@ -from typing import Callable, TypeVar +from typing import Callable, Tuple, TypeVar _Tin = TypeVar("_Tin") _Tin2 = TypeVar("_Tin2") @@ -128,3 +128,19 @@ def _intern3(input3: _Tin3) -> _Tout: return _intern2 return _intern + + +def fst(t: Tuple[_Tin, _Tin2]) -> _Tin: + """get first of tuple + >>> fst((1, 2)) == 1 + True + """ + return t[0] + + +def snd(t: Tuple[_Tin, _Tin2]) -> _Tin2: + """get second of tuple + >>> snd((1, 2)) == 2 + True + """ + return t[1]