Natural -> (listof X) - build-list
(listof X) -> (listof X) - filter
(listof X) -> (listof Y) - map
(listof X) -> Boolean - andmap
(listof X) -> Boolean - ormap
import NetInfo, { NetInfoState, NetInfoSubscription } from '@react-native-community/netinfo'; | |
import { useState, useRef, useEffect } from 'react'; | |
const useDeviceOnlineStatus = () => { | |
const [online, setOnline] = useState(false); | |
const unsubscribeRef = useRef<NetInfoSubscription | undefined>(); | |
useEffect(() => { | |
unsubscribeRef.current = NetInfo.addEventListener((state: NetInfoState) => { | |
setOnline(state.isConnected); |
const wait = async (ms: number) => | |
new Promise((resolve) => { | |
setTimeout(() => resolve(), ms); | |
}); | |
await wait(10000); // wait for 10 seconds | |
// Continue... |
import { getProviderStatusAsync, LocationProviderStatus } from 'expo-location'; | |
import { useState } from 'react'; | |
import { Platform } from 'react-native'; | |
import useInterval from 'use-interval'; | |
const useLocationProviderStatus = (delay: number = 2000) => { | |
const [locationProviderAvailable, setLocationProviderAvailable] = useState<boolean | undefined>(undefined); | |
const getLocationProviderStatus = ({ | |
gpsAvailable, |
type BST = { | |
key: number; | |
value: string; | |
left: BST | false; | |
right: BST | false; | |
} | false; | |
const BST0: BST = false; | |
const BST1: BST = { | |
key: 1, |
(define-struct node (k v l r)) | |
;; BinaryTree is one of: | |
;; - false | |
;; - (make-node Natural String BinaryTree BinaryTree) | |
(define BT0 false) | |
(define BT1 (make-node 1 "a" false false)) | |
(define BT4 (make-node 4 "d" | |
(make-node 2 "b" | |
(make-node 1 "a" false false) | |
(make-node 3 "c" false false)) |
(define (find name dir) | |
(local [(define (c1 n rdirs rimgs) | |
(or (string=? name n) | |
rdirs | |
rimgs)) | |
(define (c2 rdir rdirs) | |
(or rdir rdirs)) | |
(define (c3 img rimgs) | |
false)] | |
(fold-dir c1 c2 c3 false false dir))) |
Natural -> (listof X) - build-list
(listof X) -> (listof X) - filter
(listof X) -> (listof Y) - map
(listof X) -> Boolean - andmap
(listof X) -> Boolean - ormap
import { useState } from 'react'; | |
import useAppState from 'react-native-appstate-hook'; | |
import RNFS from 'react-native-fs'; | |
async function copyDir(source: string, destination: string) { | |
const fileChangeLog: string[] = []; | |
await copyDirRecursive(source, destination, fileChangeLog); | |
return fileChangeLog; |
// From https://stackoverflow.com/questions/44654291/is-it-good-practice-to-use-ordinal-of-enum | |
public enum Person { | |
GRANDPARENT(null), | |
PARENT(GRANDPARENT), | |
CHILD(PARENT); | |
private final Person parent; | |
private Person(Person parent) { |
// Adapted from https://howtodoinjava.com/typescript/function-overloading | |
class MiddleEarthResident { | |
name: string; | |
constructor(name: string) { | |
this.name = name; | |
} | |
} | |
class ShireResident extends MiddleEarthResident { |