Skip to content

Instantly share code, notes, and snippets.

@iamsonnn
iamsonnn / StreamUtils.java
Last active November 29, 2023 13:12
Stream Utils for handling common collection processing use cases
import java.util.*;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
public class StreamUtils {
public static <S, D> List<D> mapToList(Collection<S> sourceList, Function<S, D> mapFunction){
if (sourceList == null || sourceList.isEmpty()) return Collections.emptyList();
return sourceList
@iamsonnn
iamsonnn / vue useRefs.md
Last active January 9, 2024 04:29
Simplize Vue's template refs, make it work with IDE suggestion & compiler

Purpose: Make Vue's template ref (https://vuejs.org/guide/essentials/template-refs.html) more typescript friendly, make IDE suggestion and compiler validator better

Create a file name useRefs.ts in your utils/helpers directory

import { reactive } from 'vue'

export const useRefs = <T extends object>() => {
  const refs = reactive<T>({} as T)
  const toRef = (refName: keyof T) => (el: any) => ((refs as T)[refName as keyof T] = el)