Edit

kc3-lang/kc3/lib/kc3/0.1/list.kc3

Branch :

  • lib/kc3/0.1/list.kc3
  • ## kc3
    ## Copyright from 2022 to 2026 kmx.io <contact@kmx.io>
    ##
    ## Permission is hereby granted to use this software granted the above
    ## copyright notice and this permission paragraph are included in all
    ## copies and substantial portions of this software.
    ##
    ## THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
    ## PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
    ## AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
    ## THIS SOFTWARE.
    
    defmodule List do
    
      def all? = cfn Bool "plist_all" (List, Callable, Result)
    
      def append = cfn List "plist_init_append" (Result, List, List)
    
      def append_one = cfn List "plist_init_append_one" (Result, List, Tag)
    
      def cast = cfn List "plist_init_cast" (Result, Sym, Tag)
    
      def count = cfn List "plist_init_count" (Result, Tag)
    
      def count_items = fn {
        (list) { count_items(list, %{}) }
        ([], map) { map }
        ([first | rest], map) {
          count = if map[first] do map[first] else 0 end
          map = Map.put(map, first, count + 1)
          count_items(rest, map)
        }
      }
    
      def each = cfn Bool "plist_each" (List, Callable, Result)
    
      def filter = cfn List "plist_filter" (List, Callable, Result)
    
      def find_if = cfn Tag "plist_find_if" (List, Callable, Result)
    
      def first = fn ([a | _]) { a }
    
      def has? = cfn Bool "plist_has" (List, Tag, Result)
    
      def join = cfn Str "plist_join" (List, Str, Result)
    
      def last = cfn Tag "plist_last" (List, Result)
    
      def length = cfn Tag "kc3_plist_length" (List, Result)
    
      def map = cfn List "plist_map" (List, Callable, Result)
    
      def next = fn ([a | b]) { b }
    
      def reverse = cfn List "plist_reverse" (List, Result)
    
      def slice = cfn List "plist_slice" (List, Tag, Tag, Result)
    
      def sort = cfn List "plist_sort" (List, Result)
    
      def sort_by = cfn List "plist_sort_by" (List, Callable, Result)
    
      def to_array = cfn Array "kc3_plist_to_array" (List, Sym, Result)
    
      def unique = cfn List "plist_unique" (List, Result)
    
    end